@omnicross/core 0.1.5 → 0.1.6
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/ApiConverter.cjs +2 -2
- package/dist/ApiConverter.js +1 -1
- package/dist/{CompletionService-DdWaAxq0.d.ts → CompletionService-C3BX0Ovy.d.ts} +4 -3
- package/dist/{CompletionService-D3a47vdU.d.cts → CompletionService-kNA17cfI.d.cts} +4 -3
- package/dist/auth/GeminiCodeAssistProjectResolver.cjs +6 -5
- package/dist/auth/GeminiCodeAssistProjectResolver.js +4 -3
- package/dist/{chunk-HRRYG2AX.js → chunk-23S5OPIO.js} +10 -1
- package/dist/chunk-25GXJCEZ.cjs +40 -0
- package/dist/chunk-2JYRIADS.js +40 -0
- package/dist/{chunk-4XMYPW46.cjs → chunk-4VLRHHFE.cjs} +75 -33
- package/dist/{chunk-VACWOIRE.cjs → chunk-4VZX5F4T.cjs} +39 -15
- package/dist/{chunk-C6OV7GCC.js → chunk-6CL5HTPQ.js} +44 -2
- package/dist/chunk-6QQG7YG3.cjs +153 -0
- package/dist/{chunk-3Q6Z6JTO.cjs → chunk-6VUQPOV3.cjs} +277 -86
- package/dist/chunk-7AK7B36B.cjs +44 -0
- package/dist/{chunk-5ZQBEOMD.js → chunk-AT7B7SOZ.js} +25 -2
- package/dist/{chunk-IK3KE3AU.js → chunk-DE2SRBFZ.js} +1 -1
- package/dist/chunk-DLXZEZWO.cjs +285 -0
- package/dist/{chunk-UHGVBFU3.js → chunk-EBLFCNPY.js} +38 -14
- package/dist/chunk-EJLH6NFT.cjs +166 -0
- package/dist/chunk-HVBBDBS3.cjs +350 -0
- package/dist/{chunk-46ZIFWYG.cjs → chunk-IIRPUVPH.cjs} +7 -1
- package/dist/{chunk-JWVTXXPX.cjs → chunk-KBM2W6UY.cjs} +8 -4
- package/dist/{chunk-PG7PS2NN.cjs → chunk-KCVJWJST.cjs} +14 -2
- package/dist/chunk-LB6EBS6Y.js +69 -0
- package/dist/{chunk-IWQAX3CS.js → chunk-LVUCAWMK.js} +1 -1
- package/dist/chunk-MKF46GNZ.js +350 -0
- package/dist/{chunk-HYN75H6G.cjs → chunk-MUHWHQVM.cjs} +1 -1
- package/dist/{chunk-MFZ5437A.js → chunk-N5T4M4GU.js} +1 -1
- package/dist/{chunk-BODMAL6G.js → chunk-OEWZUX4G.js} +262 -71
- package/dist/chunk-OF3BECU2.cjs +69 -0
- package/dist/{chunk-DDMRUL76.cjs → chunk-OKMJLEXX.cjs} +5 -5
- package/dist/chunk-OPRS4IQZ.js +153 -0
- package/dist/{chunk-D3TDKWRP.js → chunk-SIZQQD6T.js} +14 -2
- package/dist/{chunk-CGKLE6IW.cjs → chunk-SQYVORNP.cjs} +1219 -510
- package/dist/{chunk-6QZGDLL4.js → chunk-TOVPMMHM.js} +5 -1
- package/dist/{chunk-FH2P4OCD.js → chunk-UDCC7EMR.js} +976 -267
- package/dist/{chunk-ZLX3KGXX.js → chunk-UX7VWA46.js} +135 -23
- package/dist/{chunk-K52THW2C.cjs → chunk-V4TXMEJS.cjs} +5 -5
- package/dist/chunk-VRFBB5DB.js +44 -0
- package/dist/chunk-WB6PH56J.js +166 -0
- package/dist/{chunk-G2UTNSGU.js → chunk-WNKWAEUR.js} +7 -1
- package/dist/{chunk-SUEGJ75D.cjs → chunk-WYTEQ4Q5.cjs} +25 -2
- package/dist/{chunk-5ENKBSWO.js → chunk-YJVHCHQX.js} +42 -6
- package/dist/{chunk-VQY5W4YW.cjs → chunk-YK57NMIF.cjs} +44 -8
- package/dist/{chunk-KFI44N2R.cjs → chunk-YNJNTCSQ.cjs} +10 -1
- package/dist/completion/ApiKeyPoolService.cjs +12 -0
- package/dist/completion/ApiKeyPoolService.d.cts +6 -0
- package/dist/completion/ApiKeyPoolService.d.ts +6 -0
- package/dist/completion/ApiKeyPoolService.js +12 -0
- package/dist/completion/CompletionService.cjs +25 -23
- package/dist/completion/CompletionService.d.cts +2 -1
- package/dist/completion/CompletionService.d.ts +2 -1
- package/dist/completion/CompletionService.js +24 -22
- package/dist/completion.cjs +25 -23
- package/dist/completion.d.cts +2 -1
- package/dist/completion.d.ts +2 -1
- package/dist/completion.js +24 -22
- package/dist/index.cjs +49 -26
- package/dist/index.d.cts +8 -8
- package/dist/index.d.ts +8 -8
- package/dist/index.js +52 -29
- package/dist/{keyPolicy-Cp0FntZl.d.ts → keyPolicy-zdWTu3CQ.d.cts} +1 -1
- package/dist/{keyPolicy-Cp0FntZl.d.cts → keyPolicy-zdWTu3CQ.d.ts} +1 -1
- package/dist/outbound-api/quotaWarn.d.cts +1 -1
- package/dist/outbound-api/quotaWarn.d.ts +1 -1
- package/dist/outbound-api/routeResolver.cjs +2 -2
- package/dist/outbound-api/routeResolver.d.cts +4 -3
- package/dist/outbound-api/routeResolver.d.ts +4 -3
- package/dist/outbound-api/routeResolver.js +1 -1
- package/dist/outbound-api/subscriptionRegistryPort.d.cts +1 -0
- package/dist/outbound-api/subscriptionRegistryPort.d.ts +1 -0
- package/dist/outbound-api/types.d.cts +3 -2
- package/dist/outbound-api/types.d.ts +3 -2
- package/dist/outbound-api.cjs +47 -24
- package/dist/outbound-api.d.cts +127 -85
- package/dist/outbound-api.d.ts +127 -85
- package/dist/outbound-api.js +50 -27
- package/dist/pipeline/AccountAllowanceScheduling.cjs +15 -0
- package/dist/pipeline/AccountAllowanceScheduling.d.cts +90 -0
- package/dist/pipeline/AccountAllowanceScheduling.d.ts +90 -0
- package/dist/pipeline/AccountAllowanceScheduling.js +15 -0
- package/dist/pipeline/AccountAllowanceStore.cjs +20 -0
- package/dist/pipeline/AccountAllowanceStore.d.cts +77 -0
- package/dist/pipeline/AccountAllowanceStore.d.ts +77 -0
- package/dist/pipeline/AccountAllowanceStore.js +20 -0
- package/dist/pipeline/AuthSource.d.cts +11 -2
- package/dist/pipeline/AuthSource.d.ts +11 -2
- package/dist/pipeline/BoundAccountSelectionError.cjs +10 -0
- package/dist/pipeline/BoundAccountSelectionError.d.cts +28 -0
- package/dist/pipeline/BoundAccountSelectionError.d.ts +28 -0
- package/dist/pipeline/BoundAccountSelectionError.js +10 -0
- package/dist/pipeline/LlmConfigProviderAuth.d.cts +1 -0
- package/dist/pipeline/LlmConfigProviderAuth.d.ts +1 -0
- package/dist/pipeline/SubscriptionAccountHealth.cjs +4 -2
- package/dist/pipeline/SubscriptionAccountHealth.d.cts +34 -6
- package/dist/pipeline/SubscriptionAccountHealth.d.ts +34 -6
- package/dist/pipeline/SubscriptionAccountHealth.js +3 -1
- package/dist/pipeline/SubscriptionAuthSource.cjs +5 -2
- package/dist/pipeline/SubscriptionAuthSource.d.cts +1 -0
- package/dist/pipeline/SubscriptionAuthSource.d.ts +1 -0
- package/dist/pipeline/SubscriptionAuthSource.js +4 -1
- package/dist/pipeline/SubscriptionAuthStrategy.d.cts +8 -3
- package/dist/pipeline/SubscriptionAuthStrategy.d.ts +8 -3
- package/dist/pipeline/executeProviderCall.cjs +2 -2
- package/dist/pipeline/executeProviderCall.d.cts +8 -3
- package/dist/pipeline/executeProviderCall.d.ts +8 -3
- package/dist/pipeline/executeProviderCall.js +1 -1
- package/dist/pipeline/resolveProviderChain.d.cts +2 -3
- package/dist/pipeline/resolveProviderChain.d.ts +2 -3
- package/dist/pipeline/resolveSubscriptionChain.d.cts +1 -0
- package/dist/pipeline/resolveSubscriptionChain.d.ts +1 -0
- package/dist/pipeline/upstreamFetch.cjs +3 -2
- package/dist/pipeline/upstreamFetch.js +2 -1
- package/dist/ports/pricing-store.d.cts +4 -3
- package/dist/ports/pricing-store.d.ts +4 -3
- package/dist/ports.d.cts +4 -3
- package/dist/ports.d.ts +4 -3
- package/dist/provider-proxy/ProviderProxy.cjs +25 -23
- package/dist/provider-proxy/ProviderProxy.d.cts +1 -0
- package/dist/provider-proxy/ProviderProxy.d.ts +1 -0
- package/dist/provider-proxy/ProviderProxy.js +24 -22
- package/dist/provider-proxy/ingress/providerProxyShared.cjs +27 -23
- package/dist/provider-proxy/ingress/providerProxyShared.d.cts +34 -5
- package/dist/provider-proxy/ingress/providerProxyShared.d.ts +34 -5
- package/dist/provider-proxy/ingress/providerProxyShared.js +26 -22
- package/dist/provider-proxy/matchText.cjs +4 -2
- package/dist/provider-proxy/matchText.d.cts +41 -6
- package/dist/provider-proxy/matchText.d.ts +41 -6
- package/dist/provider-proxy/matchText.js +3 -1
- package/dist/provider-proxy/types.d.cts +30 -2
- package/dist/provider-proxy/types.d.ts +30 -2
- package/dist/provider-proxy.cjs +25 -23
- package/dist/provider-proxy.d.cts +1 -0
- package/dist/provider-proxy.d.ts +1 -0
- package/dist/provider-proxy.js +24 -22
- package/dist/{routeResolver-C4T7yClx.d.ts → routeResolver-CHTv_Bs5.d.ts} +1 -1
- package/dist/{routeResolver-CB3tvJKy.d.cts → routeResolver-kepxnfcC.d.cts} +1 -1
- package/dist/transformer/TransformerChainExecutor.cjs +2 -2
- package/dist/transformer/TransformerChainExecutor.js +1 -1
- package/dist/transformer/transformers/AnthropicTransformer.cjs +2 -2
- package/dist/transformer/transformers/AnthropicTransformer.js +1 -1
- package/dist/transformer/transformers/GeminiCodeAssistTransformer.cjs +3 -3
- package/dist/transformer/transformers/GeminiCodeAssistTransformer.js +2 -2
- package/dist/transformer/transformers/GeminiTransformer.cjs +3 -3
- package/dist/transformer/transformers/GeminiTransformer.js +2 -2
- package/dist/transformer/transformers/OpenAIResponseTransformer.cjs +2 -2
- package/dist/transformer/transformers/OpenAIResponseTransformer.d.cts +1 -1
- package/dist/transformer/transformers/OpenAIResponseTransformer.d.ts +1 -1
- package/dist/transformer/transformers/OpenAIResponseTransformer.js +1 -1
- package/dist/transformer/transformers/OpenAITransformer.cjs +6 -0
- package/dist/transformer/transformers/OpenAITransformer.d.cts +68 -0
- package/dist/transformer/transformers/OpenAITransformer.d.ts +68 -0
- package/dist/transformer/transformers/OpenAITransformer.js +6 -0
- package/dist/transformer/transformers.cjs +8 -14
- package/dist/transformer/transformers.d.cts +12 -48
- package/dist/transformer/transformers.d.ts +12 -48
- package/dist/transformer/transformers.js +12 -18
- package/dist/transformer/types.d.cts +17 -0
- package/dist/transformer/types.d.ts +17 -0
- package/dist/transformer.cjs +10 -11
- package/dist/transformer.d.cts +1 -2
- package/dist/transformer.d.ts +1 -2
- package/dist/transformer.js +9 -10
- package/dist/{types-B8Arpxn0.d.cts → types-H3wGZSOo.d.cts} +134 -7
- package/dist/{types-lgPYQuZS.d.ts → types-hsoKrVQS.d.ts} +134 -7
- package/dist/usage/pricing-engine.cjs +2 -2
- package/dist/usage/pricing-engine.d.cts +9 -1
- package/dist/usage/pricing-engine.d.ts +9 -1
- package/dist/usage/pricing-engine.js +1 -1
- package/dist/usage.cjs +2 -2
- package/dist/usage.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-7FEBOPJO.cjs +0 -50
- package/dist/chunk-DWKQZ2SK.cjs +0 -254
- package/dist/chunk-IAXWICZU.js +0 -69
- package/dist/chunk-IB3FDI4O.js +0 -50
- package/dist/chunk-OQWKZCXP.js +0 -242
- package/dist/chunk-QWBWGODS.cjs +0 -69
- package/dist/chunk-YMFAJFQT.cjs +0 -173
- package/dist/chunk-ZCIQ3L3R.cjs +0 -242
- package/dist/chunk-ZJZAOKI7.js +0 -254
- package/dist/transformer/transformers/OpenCodeGoTransformer.cjs +0 -6
- package/dist/transformer/transformers/OpenCodeGoTransformer.d.cts +0 -51
- package/dist/transformer/transformers/OpenCodeGoTransformer.d.ts +0 -51
- package/dist/transformer/transformers/OpenCodeGoTransformer.js +0 -6
- package/dist/transformer/transformers/ReasoningTransformer.cjs +0 -6
- package/dist/transformer/transformers/ReasoningTransformer.d.cts +0 -47
- package/dist/transformer/transformers/ReasoningTransformer.d.ts +0 -47
- package/dist/transformer/transformers/ReasoningTransformer.js +0 -6
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { SubscriptionProviderId } from '@omnicross/contracts/subscription-types';
|
|
2
|
+
import { a as AllowanceSchedulingConfig } from '../types-hsoKrVQS.js';
|
|
3
|
+
import { AccountAllowanceStore } from './AccountAllowanceStore.js';
|
|
4
|
+
import '@omnicross/contracts/account-tokens-types';
|
|
5
|
+
import '@omnicross/contracts/audit-types';
|
|
6
|
+
import '@omnicross/contracts/billing-types';
|
|
7
|
+
import '@omnicross/contracts/health-logging-types';
|
|
8
|
+
import '@omnicross/contracts/voucher-types';
|
|
9
|
+
import '@omnicross/contracts/webhook-types';
|
|
10
|
+
import '../logger-4GvQNzhE.js';
|
|
11
|
+
import '../ports/provider-config-source.js';
|
|
12
|
+
import '@omnicross/contracts/llm-config';
|
|
13
|
+
import '../transformer/types.js';
|
|
14
|
+
import '../transformer/TransformerService.js';
|
|
15
|
+
import '../ProviderProxy-C-xqrkKi.js';
|
|
16
|
+
import '../provider-proxy/types.js';
|
|
17
|
+
import 'node:http';
|
|
18
|
+
import '@omnicross/contracts/completion-types';
|
|
19
|
+
import '@omnicross/contracts/usage-types';
|
|
20
|
+
import '../completion/ApiKeyPoolService.js';
|
|
21
|
+
import './AuthSource.js';
|
|
22
|
+
import './BoundAccountSelectionError.js';
|
|
23
|
+
import './SubscriptionAuthSource.js';
|
|
24
|
+
import './SubscriptionAuthStrategy.js';
|
|
25
|
+
import '../ports/web-search-backend.js';
|
|
26
|
+
import '@omnicross/contracts/websearch-types';
|
|
27
|
+
import '../keyPolicy-zdWTu3CQ.js';
|
|
28
|
+
import '@omnicross/contracts/account-allowance-types';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Default-off allowance-aware scheduling policy.
|
|
32
|
+
*
|
|
33
|
+
* This layer consumes only normalized, secret-free snapshots. Missing, stale,
|
|
34
|
+
* unsupported, or reset-expired data is deliberately ignored so telemetry can
|
|
35
|
+
* never strand an account by accident.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
type AllowanceSchedulingAction = 'normal' | 'demote' | 'pause' | 'ignore';
|
|
39
|
+
interface AllowanceSchedulingDecision {
|
|
40
|
+
providerId: SubscriptionProviderId;
|
|
41
|
+
accountId: string;
|
|
42
|
+
action: AllowanceSchedulingAction;
|
|
43
|
+
reason: 'policy-disabled' | 'provider-unsupported' | 'snapshot-missing' | 'snapshot-not-fresh' | 'below-threshold' | 'demote-threshold' | 'pause-threshold';
|
|
44
|
+
basePriority: number;
|
|
45
|
+
effectivePriority: number;
|
|
46
|
+
schedulable: boolean;
|
|
47
|
+
usedPercent?: number;
|
|
48
|
+
observedAt?: string;
|
|
49
|
+
resumeAt?: string;
|
|
50
|
+
decidedAt: string;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Safe, structured signal emitted only when an enabled allowance policy paused
|
|
54
|
+
* every otherwise eligible account. Request ingress maps it to HTTP 429 instead
|
|
55
|
+
* of disguising a local scheduling decision as an upstream 5xx.
|
|
56
|
+
*/
|
|
57
|
+
declare class AccountAllowanceExhaustedError extends Error {
|
|
58
|
+
readonly providerId: SubscriptionProviderId;
|
|
59
|
+
readonly resumeAt?: string | undefined;
|
|
60
|
+
readonly code = "account_allowance_exhausted";
|
|
61
|
+
readonly status = 429;
|
|
62
|
+
constructor(providerId: SubscriptionProviderId, resumeAt?: string | undefined);
|
|
63
|
+
}
|
|
64
|
+
/** Structural guard survives package/bundle boundaries and never inspects secrets. */
|
|
65
|
+
declare function isAccountAllowanceExhaustedError(error: unknown): error is AccountAllowanceExhaustedError;
|
|
66
|
+
declare class AccountAllowanceScheduling {
|
|
67
|
+
private readonly store;
|
|
68
|
+
private readonly now;
|
|
69
|
+
private config;
|
|
70
|
+
private readonly history;
|
|
71
|
+
private readonly lastRecorded;
|
|
72
|
+
constructor(store?: AccountAllowanceStore, now?: () => number);
|
|
73
|
+
configure(config: AllowanceSchedulingConfig | undefined): void;
|
|
74
|
+
getConfig(): AllowanceSchedulingConfig;
|
|
75
|
+
evaluate(providerId: SubscriptionProviderId, accountId: string, basePriority: number, now?: number): AllowanceSchedulingDecision;
|
|
76
|
+
/**
|
|
77
|
+
* Project the current policy result without recording an applied decision.
|
|
78
|
+
* Admin/read-model callers use this so polling an account list never creates
|
|
79
|
+
* synthetic demotion/pause history entries.
|
|
80
|
+
*/
|
|
81
|
+
preview(providerId: SubscriptionProviderId, accountId: string, basePriority: number, now?: number): AllowanceSchedulingDecision;
|
|
82
|
+
private decide;
|
|
83
|
+
getHistory(): AllowanceSchedulingDecision[];
|
|
84
|
+
clearHistory(): void;
|
|
85
|
+
private recordApplied;
|
|
86
|
+
}
|
|
87
|
+
declare function getSharedAccountAllowanceScheduling(): AccountAllowanceScheduling;
|
|
88
|
+
declare function __resetSharedAccountAllowanceSchedulingForTests(): void;
|
|
89
|
+
|
|
90
|
+
export { AccountAllowanceExhaustedError, AccountAllowanceScheduling, type AllowanceSchedulingAction, type AllowanceSchedulingDecision, __resetSharedAccountAllowanceSchedulingForTests, getSharedAccountAllowanceScheduling, isAccountAllowanceExhaustedError };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AccountAllowanceExhaustedError,
|
|
3
|
+
AccountAllowanceScheduling,
|
|
4
|
+
__resetSharedAccountAllowanceSchedulingForTests,
|
|
5
|
+
getSharedAccountAllowanceScheduling,
|
|
6
|
+
isAccountAllowanceExhaustedError
|
|
7
|
+
} from "../chunk-OPRS4IQZ.js";
|
|
8
|
+
import "../chunk-MKF46GNZ.js";
|
|
9
|
+
export {
|
|
10
|
+
AccountAllowanceExhaustedError,
|
|
11
|
+
AccountAllowanceScheduling,
|
|
12
|
+
__resetSharedAccountAllowanceSchedulingForTests,
|
|
13
|
+
getSharedAccountAllowanceScheduling,
|
|
14
|
+
isAccountAllowanceExhaustedError
|
|
15
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
var _chunkHVBBDBS3cjs = require('../chunk-HVBBDBS3.cjs');
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
exports.AccountAllowanceStore = _chunkHVBBDBS3cjs.AccountAllowanceStore; exports.DEFAULT_ALLOWANCE_MAX_SNAPSHOTS = _chunkHVBBDBS3cjs.DEFAULT_ALLOWANCE_MAX_SNAPSHOTS; exports.DEFAULT_CODEX_ALLOWANCE_FRESH_MS = _chunkHVBBDBS3cjs.DEFAULT_CODEX_ALLOWANCE_FRESH_MS; exports.__resetSharedAccountAllowanceStoreForTests = _chunkHVBBDBS3cjs.__resetSharedAccountAllowanceStoreForTests; exports.getSharedAccountAllowanceStore = _chunkHVBBDBS3cjs.getSharedAccountAllowanceStore; exports.normalizeAccountAllowanceSnapshot = _chunkHVBBDBS3cjs.normalizeAccountAllowanceSnapshot; exports.parseCodexAllowanceHeaders = _chunkHVBBDBS3cjs.parseCodexAllowanceHeaders; exports.setSharedAccountAllowanceStore = _chunkHVBBDBS3cjs.setSharedAccountAllowanceStore;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { AccountAllowanceSnapshot } from '@omnicross/contracts/account-allowance-types';
|
|
2
|
+
import { SubscriptionProviderId } from '@omnicross/contracts/subscription-types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Secret-free upstream account allowance snapshots.
|
|
6
|
+
*
|
|
7
|
+
* Claude actively populates this store from the daemon. Codex is observed at the
|
|
8
|
+
* core egress seam so the response headers are attributed to the exact account id
|
|
9
|
+
* selected for that request. Only normalized numbers are retained; raw headers
|
|
10
|
+
* and credentials never enter the store. A host may inject a small persistence
|
|
11
|
+
* port; core deliberately does not know where that host stores the snapshot.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
declare const DEFAULT_CODEX_ALLOWANCE_FRESH_MS: number;
|
|
15
|
+
declare const DEFAULT_ALLOWANCE_MAX_SNAPSHOTS = 256;
|
|
16
|
+
type AllowanceHeadersLike = Headers | Record<string, string | string[] | number | null | undefined>;
|
|
17
|
+
interface CodexAllowanceWindowObservation {
|
|
18
|
+
usedPercent?: number;
|
|
19
|
+
resetAfterSeconds?: number;
|
|
20
|
+
windowMinutes?: number;
|
|
21
|
+
}
|
|
22
|
+
interface CodexAllowanceObservation {
|
|
23
|
+
primary?: CodexAllowanceWindowObservation;
|
|
24
|
+
secondary?: CodexAllowanceWindowObservation;
|
|
25
|
+
primaryOverSecondaryLimitPercent?: number;
|
|
26
|
+
}
|
|
27
|
+
/** Host-owned persistence seam for normalized allowance snapshots. */
|
|
28
|
+
interface AccountAllowancePersistence {
|
|
29
|
+
/** Return the decoded file payload, or any value for the store to validate. */
|
|
30
|
+
load(): unknown;
|
|
31
|
+
/** Replace the durable snapshot with this already-normalized bounded list. */
|
|
32
|
+
save(snapshots: readonly AccountAllowanceSnapshot[]): void;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Pick and normalize only the public DTO fields. This is used for both live
|
|
36
|
+
* writes and restart loads, so a structurally-cast object can never smuggle raw
|
|
37
|
+
* headers, response bodies, or token fields into the cache.
|
|
38
|
+
*/
|
|
39
|
+
declare function normalizeAccountAllowanceSnapshot(value: unknown): AccountAllowanceSnapshot | null;
|
|
40
|
+
/** Parse only the documented numeric Codex allowance headers. */
|
|
41
|
+
declare function parseCodexAllowanceHeaders(headers: AllowanceHeadersLike): CodexAllowanceObservation | null;
|
|
42
|
+
/** In-memory allowance projection shared by serving/admin with optional host persistence. */
|
|
43
|
+
declare class AccountAllowanceStore {
|
|
44
|
+
private readonly now;
|
|
45
|
+
private readonly codexFreshMs;
|
|
46
|
+
private readonly persistence?;
|
|
47
|
+
private readonly snapshots;
|
|
48
|
+
private readonly maxSnapshots;
|
|
49
|
+
constructor(now?: () => number, codexFreshMs?: number, persistence?: AccountAllowancePersistence | undefined, maxSnapshots?: number);
|
|
50
|
+
set(snapshot: AccountAllowanceSnapshot): void;
|
|
51
|
+
delete(providerId: SubscriptionProviderId, accountId: string): void;
|
|
52
|
+
/** Remove rows that no longer correspond to a configured account. */
|
|
53
|
+
pruneToKnownAccounts(accounts: Iterable<{
|
|
54
|
+
providerId: SubscriptionProviderId;
|
|
55
|
+
accountId: string;
|
|
56
|
+
}>): number;
|
|
57
|
+
get(providerId: SubscriptionProviderId, accountId: string, now?: number): AccountAllowanceSnapshot | null;
|
|
58
|
+
list(filter?: {
|
|
59
|
+
providerId?: SubscriptionProviderId;
|
|
60
|
+
accountId?: string;
|
|
61
|
+
}, now?: number): AccountAllowanceSnapshot[];
|
|
62
|
+
/**
|
|
63
|
+
* Merge one real Codex upstream response into the selected account's snapshot.
|
|
64
|
+
* A response with no recognized headers is a strict no-op, and a partial header
|
|
65
|
+
* set preserves previous values while marking untouched windows stale.
|
|
66
|
+
*/
|
|
67
|
+
recordCodexHeaders(accountId: string, headers: AllowanceHeadersLike, observedMs?: number): AccountAllowanceSnapshot | null;
|
|
68
|
+
clear(): void;
|
|
69
|
+
private loadPersisted;
|
|
70
|
+
private persist;
|
|
71
|
+
}
|
|
72
|
+
declare function getSharedAccountAllowanceStore(): AccountAllowanceStore;
|
|
73
|
+
declare function setSharedAccountAllowanceStore(store: AccountAllowanceStore): void;
|
|
74
|
+
/** Test/daemon teardown seam. */
|
|
75
|
+
declare function __resetSharedAccountAllowanceStoreForTests(): void;
|
|
76
|
+
|
|
77
|
+
export { type AccountAllowancePersistence, AccountAllowanceStore, type AllowanceHeadersLike, type CodexAllowanceObservation, type CodexAllowanceWindowObservation, DEFAULT_ALLOWANCE_MAX_SNAPSHOTS, DEFAULT_CODEX_ALLOWANCE_FRESH_MS, __resetSharedAccountAllowanceStoreForTests, getSharedAccountAllowanceStore, normalizeAccountAllowanceSnapshot, parseCodexAllowanceHeaders, setSharedAccountAllowanceStore };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { AccountAllowanceSnapshot } from '@omnicross/contracts/account-allowance-types';
|
|
2
|
+
import { SubscriptionProviderId } from '@omnicross/contracts/subscription-types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Secret-free upstream account allowance snapshots.
|
|
6
|
+
*
|
|
7
|
+
* Claude actively populates this store from the daemon. Codex is observed at the
|
|
8
|
+
* core egress seam so the response headers are attributed to the exact account id
|
|
9
|
+
* selected for that request. Only normalized numbers are retained; raw headers
|
|
10
|
+
* and credentials never enter the store. A host may inject a small persistence
|
|
11
|
+
* port; core deliberately does not know where that host stores the snapshot.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
declare const DEFAULT_CODEX_ALLOWANCE_FRESH_MS: number;
|
|
15
|
+
declare const DEFAULT_ALLOWANCE_MAX_SNAPSHOTS = 256;
|
|
16
|
+
type AllowanceHeadersLike = Headers | Record<string, string | string[] | number | null | undefined>;
|
|
17
|
+
interface CodexAllowanceWindowObservation {
|
|
18
|
+
usedPercent?: number;
|
|
19
|
+
resetAfterSeconds?: number;
|
|
20
|
+
windowMinutes?: number;
|
|
21
|
+
}
|
|
22
|
+
interface CodexAllowanceObservation {
|
|
23
|
+
primary?: CodexAllowanceWindowObservation;
|
|
24
|
+
secondary?: CodexAllowanceWindowObservation;
|
|
25
|
+
primaryOverSecondaryLimitPercent?: number;
|
|
26
|
+
}
|
|
27
|
+
/** Host-owned persistence seam for normalized allowance snapshots. */
|
|
28
|
+
interface AccountAllowancePersistence {
|
|
29
|
+
/** Return the decoded file payload, or any value for the store to validate. */
|
|
30
|
+
load(): unknown;
|
|
31
|
+
/** Replace the durable snapshot with this already-normalized bounded list. */
|
|
32
|
+
save(snapshots: readonly AccountAllowanceSnapshot[]): void;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Pick and normalize only the public DTO fields. This is used for both live
|
|
36
|
+
* writes and restart loads, so a structurally-cast object can never smuggle raw
|
|
37
|
+
* headers, response bodies, or token fields into the cache.
|
|
38
|
+
*/
|
|
39
|
+
declare function normalizeAccountAllowanceSnapshot(value: unknown): AccountAllowanceSnapshot | null;
|
|
40
|
+
/** Parse only the documented numeric Codex allowance headers. */
|
|
41
|
+
declare function parseCodexAllowanceHeaders(headers: AllowanceHeadersLike): CodexAllowanceObservation | null;
|
|
42
|
+
/** In-memory allowance projection shared by serving/admin with optional host persistence. */
|
|
43
|
+
declare class AccountAllowanceStore {
|
|
44
|
+
private readonly now;
|
|
45
|
+
private readonly codexFreshMs;
|
|
46
|
+
private readonly persistence?;
|
|
47
|
+
private readonly snapshots;
|
|
48
|
+
private readonly maxSnapshots;
|
|
49
|
+
constructor(now?: () => number, codexFreshMs?: number, persistence?: AccountAllowancePersistence | undefined, maxSnapshots?: number);
|
|
50
|
+
set(snapshot: AccountAllowanceSnapshot): void;
|
|
51
|
+
delete(providerId: SubscriptionProviderId, accountId: string): void;
|
|
52
|
+
/** Remove rows that no longer correspond to a configured account. */
|
|
53
|
+
pruneToKnownAccounts(accounts: Iterable<{
|
|
54
|
+
providerId: SubscriptionProviderId;
|
|
55
|
+
accountId: string;
|
|
56
|
+
}>): number;
|
|
57
|
+
get(providerId: SubscriptionProviderId, accountId: string, now?: number): AccountAllowanceSnapshot | null;
|
|
58
|
+
list(filter?: {
|
|
59
|
+
providerId?: SubscriptionProviderId;
|
|
60
|
+
accountId?: string;
|
|
61
|
+
}, now?: number): AccountAllowanceSnapshot[];
|
|
62
|
+
/**
|
|
63
|
+
* Merge one real Codex upstream response into the selected account's snapshot.
|
|
64
|
+
* A response with no recognized headers is a strict no-op, and a partial header
|
|
65
|
+
* set preserves previous values while marking untouched windows stale.
|
|
66
|
+
*/
|
|
67
|
+
recordCodexHeaders(accountId: string, headers: AllowanceHeadersLike, observedMs?: number): AccountAllowanceSnapshot | null;
|
|
68
|
+
clear(): void;
|
|
69
|
+
private loadPersisted;
|
|
70
|
+
private persist;
|
|
71
|
+
}
|
|
72
|
+
declare function getSharedAccountAllowanceStore(): AccountAllowanceStore;
|
|
73
|
+
declare function setSharedAccountAllowanceStore(store: AccountAllowanceStore): void;
|
|
74
|
+
/** Test/daemon teardown seam. */
|
|
75
|
+
declare function __resetSharedAccountAllowanceStoreForTests(): void;
|
|
76
|
+
|
|
77
|
+
export { type AccountAllowancePersistence, AccountAllowanceStore, type AllowanceHeadersLike, type CodexAllowanceObservation, type CodexAllowanceWindowObservation, DEFAULT_ALLOWANCE_MAX_SNAPSHOTS, DEFAULT_CODEX_ALLOWANCE_FRESH_MS, __resetSharedAccountAllowanceStoreForTests, getSharedAccountAllowanceStore, normalizeAccountAllowanceSnapshot, parseCodexAllowanceHeaders, setSharedAccountAllowanceStore };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AccountAllowanceStore,
|
|
3
|
+
DEFAULT_ALLOWANCE_MAX_SNAPSHOTS,
|
|
4
|
+
DEFAULT_CODEX_ALLOWANCE_FRESH_MS,
|
|
5
|
+
__resetSharedAccountAllowanceStoreForTests,
|
|
6
|
+
getSharedAccountAllowanceStore,
|
|
7
|
+
normalizeAccountAllowanceSnapshot,
|
|
8
|
+
parseCodexAllowanceHeaders,
|
|
9
|
+
setSharedAccountAllowanceStore
|
|
10
|
+
} from "../chunk-MKF46GNZ.js";
|
|
11
|
+
export {
|
|
12
|
+
AccountAllowanceStore,
|
|
13
|
+
DEFAULT_ALLOWANCE_MAX_SNAPSHOTS,
|
|
14
|
+
DEFAULT_CODEX_ALLOWANCE_FRESH_MS,
|
|
15
|
+
__resetSharedAccountAllowanceStoreForTests,
|
|
16
|
+
getSharedAccountAllowanceStore,
|
|
17
|
+
normalizeAccountAllowanceSnapshot,
|
|
18
|
+
parseCodexAllowanceHeaders,
|
|
19
|
+
setSharedAccountAllowanceStore
|
|
20
|
+
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { BoundAccountFallbackPolicy } from './BoundAccountSelectionError.cjs';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* AuthSource — unified outbound-authentication strategy for the provider
|
|
3
5
|
* request pipeline.
|
|
@@ -54,10 +56,17 @@ interface AuthApplyHints {
|
|
|
54
56
|
reportSelection?: (accountId: string, isActive: boolean, remappedModel?: string) => void;
|
|
55
57
|
/**
|
|
56
58
|
* OPTIONAL preferred subscription account id (provider/subscription duality).
|
|
57
|
-
* When set
|
|
58
|
-
*
|
|
59
|
+
* When set, strict is the default; only the explicit `'pool'` policy permits
|
|
60
|
+
* pool fallback. BYO auth sources ignore both binding hints.
|
|
59
61
|
*/
|
|
60
62
|
preferredAccountId?: string;
|
|
63
|
+
/** Optional account group selected by a resource-level gateway binding. */
|
|
64
|
+
preferredAccountGroup?: string;
|
|
65
|
+
/**
|
|
66
|
+
* Binding behavior. `'pool'` is an explicit opt-in; any other value used
|
|
67
|
+
* with a preferred account is treated as strict by the selector.
|
|
68
|
+
*/
|
|
69
|
+
boundAccountFallbackPolicy?: BoundAccountFallbackPolicy;
|
|
61
70
|
}
|
|
62
71
|
/**
|
|
63
72
|
* Result of {@link AuthSource.onResult}.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { BoundAccountFallbackPolicy } from './BoundAccountSelectionError.js';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* AuthSource — unified outbound-authentication strategy for the provider
|
|
3
5
|
* request pipeline.
|
|
@@ -54,10 +56,17 @@ interface AuthApplyHints {
|
|
|
54
56
|
reportSelection?: (accountId: string, isActive: boolean, remappedModel?: string) => void;
|
|
55
57
|
/**
|
|
56
58
|
* OPTIONAL preferred subscription account id (provider/subscription duality).
|
|
57
|
-
* When set
|
|
58
|
-
*
|
|
59
|
+
* When set, strict is the default; only the explicit `'pool'` policy permits
|
|
60
|
+
* pool fallback. BYO auth sources ignore both binding hints.
|
|
59
61
|
*/
|
|
60
62
|
preferredAccountId?: string;
|
|
63
|
+
/** Optional account group selected by a resource-level gateway binding. */
|
|
64
|
+
preferredAccountGroup?: string;
|
|
65
|
+
/**
|
|
66
|
+
* Binding behavior. `'pool'` is an explicit opt-in; any other value used
|
|
67
|
+
* with a preferred account is treated as strict by the selector.
|
|
68
|
+
*/
|
|
69
|
+
boundAccountFallbackPolicy?: BoundAccountFallbackPolicy;
|
|
61
70
|
}
|
|
62
71
|
/**
|
|
63
72
|
* Result of {@link AuthSource.onResult}.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
var _chunk25GXJCEZcjs = require('../chunk-25GXJCEZ.cjs');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
exports.BoundAccountSelectionError = _chunk25GXJCEZcjs.BoundAccountSelectionError; exports.boundAccountSelectionMessage = _chunk25GXJCEZcjs.boundAccountSelectionMessage; exports.isBoundAccountSelectionError = _chunk25GXJCEZcjs.isBoundAccountSelectionError;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Secret-free failure contract for a strict outbound subscription-account
|
|
3
|
+
* binding. The selector throws this value only when an endpoint explicitly (or
|
|
4
|
+
* by the migrated default) requires its bound account to serve the request.
|
|
5
|
+
*/
|
|
6
|
+
/** Persisted policy for an endpoint that binds a subscription account. */
|
|
7
|
+
type BoundAccountFallbackPolicy = 'strict' | 'pool';
|
|
8
|
+
/** Bounded reasons a strict bound account can refuse a request. */
|
|
9
|
+
type BoundAccountSelectionFailureReason = 'unavailable' | 'not-found' | 'disabled' | 'unhealthy' | 'model-incompatible' | 'allowance-paused' | 'empty-token';
|
|
10
|
+
/** Return the fixed public message for a validated failure reason. */
|
|
11
|
+
declare function boundAccountSelectionMessage(reason: BoundAccountSelectionFailureReason): string;
|
|
12
|
+
/**
|
|
13
|
+
* Stable, non-secret error thrown by strict account selection. Account ids and
|
|
14
|
+
* token material are intentionally absent from both the message and the wire
|
|
15
|
+
* projection; the reason is a small fixed vocabulary.
|
|
16
|
+
*/
|
|
17
|
+
declare class BoundAccountSelectionError extends Error {
|
|
18
|
+
readonly providerId: string;
|
|
19
|
+
readonly reason: BoundAccountSelectionFailureReason;
|
|
20
|
+
readonly resumeAt?: string | undefined;
|
|
21
|
+
readonly code: "bound_account_unavailable";
|
|
22
|
+
readonly status: 429 | 503;
|
|
23
|
+
constructor(providerId: string, reason: BoundAccountSelectionFailureReason, resumeAt?: string | undefined);
|
|
24
|
+
}
|
|
25
|
+
/** Structural guard that survives package/bundle boundaries. */
|
|
26
|
+
declare function isBoundAccountSelectionError(error: unknown): error is BoundAccountSelectionError;
|
|
27
|
+
|
|
28
|
+
export { type BoundAccountFallbackPolicy, BoundAccountSelectionError, type BoundAccountSelectionFailureReason, boundAccountSelectionMessage, isBoundAccountSelectionError };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Secret-free failure contract for a strict outbound subscription-account
|
|
3
|
+
* binding. The selector throws this value only when an endpoint explicitly (or
|
|
4
|
+
* by the migrated default) requires its bound account to serve the request.
|
|
5
|
+
*/
|
|
6
|
+
/** Persisted policy for an endpoint that binds a subscription account. */
|
|
7
|
+
type BoundAccountFallbackPolicy = 'strict' | 'pool';
|
|
8
|
+
/** Bounded reasons a strict bound account can refuse a request. */
|
|
9
|
+
type BoundAccountSelectionFailureReason = 'unavailable' | 'not-found' | 'disabled' | 'unhealthy' | 'model-incompatible' | 'allowance-paused' | 'empty-token';
|
|
10
|
+
/** Return the fixed public message for a validated failure reason. */
|
|
11
|
+
declare function boundAccountSelectionMessage(reason: BoundAccountSelectionFailureReason): string;
|
|
12
|
+
/**
|
|
13
|
+
* Stable, non-secret error thrown by strict account selection. Account ids and
|
|
14
|
+
* token material are intentionally absent from both the message and the wire
|
|
15
|
+
* projection; the reason is a small fixed vocabulary.
|
|
16
|
+
*/
|
|
17
|
+
declare class BoundAccountSelectionError extends Error {
|
|
18
|
+
readonly providerId: string;
|
|
19
|
+
readonly reason: BoundAccountSelectionFailureReason;
|
|
20
|
+
readonly resumeAt?: string | undefined;
|
|
21
|
+
readonly code: "bound_account_unavailable";
|
|
22
|
+
readonly status: 429 | 503;
|
|
23
|
+
constructor(providerId: string, reason: BoundAccountSelectionFailureReason, resumeAt?: string | undefined);
|
|
24
|
+
}
|
|
25
|
+
/** Structural guard that survives package/bundle boundaries. */
|
|
26
|
+
declare function isBoundAccountSelectionError(error: unknown): error is BoundAccountSelectionError;
|
|
27
|
+
|
|
28
|
+
export { type BoundAccountFallbackPolicy, BoundAccountSelectionError, type BoundAccountSelectionFailureReason, boundAccountSelectionMessage, isBoundAccountSelectionError };
|
|
@@ -2,6 +2,7 @@ import { LLMProvider } from '@omnicross/contracts/llm-config';
|
|
|
2
2
|
import { ApiKeyPoolService } from '../completion/ApiKeyPoolService.cjs';
|
|
3
3
|
import { AuthSource, AuthApplyHints, AuthResultOutcome } from './AuthSource.cjs';
|
|
4
4
|
import '../logger-4GvQNzhE.cjs';
|
|
5
|
+
import './BoundAccountSelectionError.cjs';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* LlmConfigProviderAuth — `AuthSource` for LLM-config provider rows.
|
|
@@ -2,6 +2,7 @@ import { LLMProvider } from '@omnicross/contracts/llm-config';
|
|
|
2
2
|
import { ApiKeyPoolService } from '../completion/ApiKeyPoolService.js';
|
|
3
3
|
import { AuthSource, AuthApplyHints, AuthResultOutcome } from './AuthSource.js';
|
|
4
4
|
import '../logger-4GvQNzhE.js';
|
|
5
|
+
import './BoundAccountSelectionError.js';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* LlmConfigProviderAuth — `AuthSource` for LLM-config provider rows.
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
var _chunkVQY5W4YWcjs = require('../chunk-VQY5W4YW.cjs');
|
|
12
11
|
|
|
12
|
+
var _chunkYK57NMIFcjs = require('../chunk-YK57NMIF.cjs');
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
|
|
@@ -19,4 +19,6 @@ var _chunkVQY5W4YWcjs = require('../chunk-VQY5W4YW.cjs');
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
exports.ACCOUNT_HEALTH_DIAGNOSTIC_LIMIT = _chunkYK57NMIFcjs.ACCOUNT_HEALTH_DIAGNOSTIC_LIMIT; exports.AUTH_ERROR_TTL_MS = _chunkYK57NMIFcjs.AUTH_ERROR_TTL_MS; exports.OVERLOAD_ENABLED_DEFAULT = _chunkYK57NMIFcjs.OVERLOAD_ENABLED_DEFAULT; exports.OVERLOAD_TTL_MS = _chunkYK57NMIFcjs.OVERLOAD_TTL_MS; exports.SERVER_ERROR_TTL_MS = _chunkYK57NMIFcjs.SERVER_ERROR_TTL_MS; exports.SubscriptionAccountHealth = _chunkYK57NMIFcjs.SubscriptionAccountHealth; exports.__resetSharedAccountHealthForTests = _chunkYK57NMIFcjs.__resetSharedAccountHealthForTests; exports.getSharedAccountHealth = _chunkYK57NMIFcjs.getSharedAccountHealth; exports.resolveResetSeconds = _chunkYK57NMIFcjs.resolveResetSeconds; exports.setSharedAccountHealth = _chunkYK57NMIFcjs.setSharedAccountHealth;
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
declare const OVERLOAD_TTL_MS: number;
|
|
28
28
|
/** 529 overload cooldown enabled by default (LEAD OQ1). */
|
|
29
29
|
declare const OVERLOAD_ENABLED_DEFAULT = true;
|
|
30
|
-
/** Transient cooldown for a final
|
|
30
|
+
/** Transient cooldown for a final 401 or non-ban 403 response. */
|
|
31
31
|
declare const AUTH_ERROR_TTL_MS: number;
|
|
32
|
-
/** Transient cooldown for a 5xx
|
|
32
|
+
/** Transient cooldown for a 5xx response or network failure. */
|
|
33
33
|
declare const SERVER_ERROR_TTL_MS: number;
|
|
34
34
|
/** Per-account health record (all timers are epoch ms). Absent fields ⇒ healthy. */
|
|
35
35
|
interface HealthRecord {
|
|
@@ -89,6 +89,30 @@ interface AccountAnomalyEvent {
|
|
|
89
89
|
}
|
|
90
90
|
/** An anomaly listener (fire-and-forget; the emitter never awaits it). */
|
|
91
91
|
type AccountAnomalyListener = (event: AccountAnomalyEvent) => void;
|
|
92
|
+
/**
|
|
93
|
+
* Admin-readable projection of the existing health event stream. It is kept in
|
|
94
|
+
* the tracker itself so webhooks and diagnostics consume the same edge events;
|
|
95
|
+
* this is not a second marking/event mechanism. Only opaque ids, timestamps,
|
|
96
|
+
* and coarse states are retained.
|
|
97
|
+
*/
|
|
98
|
+
type AccountHealthDiagnostic = {
|
|
99
|
+
kind: 'health-anomaly';
|
|
100
|
+
providerId: string;
|
|
101
|
+
accountId: string;
|
|
102
|
+
at: number;
|
|
103
|
+
state: AccountAnomalyState;
|
|
104
|
+
} | {
|
|
105
|
+
kind: 'health-recovery';
|
|
106
|
+
providerId: string;
|
|
107
|
+
accountId: string;
|
|
108
|
+
at: number;
|
|
109
|
+
};
|
|
110
|
+
interface AccountHealthDiagnosticFilter {
|
|
111
|
+
providerId?: string;
|
|
112
|
+
accountId?: string;
|
|
113
|
+
limit?: number;
|
|
114
|
+
}
|
|
115
|
+
declare const ACCOUNT_HEALTH_DIAGNOSTIC_LIMIT = 200;
|
|
92
116
|
/** The inputs one upstream attempt contributes to health marking (design D3). */
|
|
93
117
|
interface RecordUpstreamOutcomeInput {
|
|
94
118
|
/** The final HTTP status, or `null` for a thrown / network failure. */
|
|
@@ -134,6 +158,7 @@ declare class SubscriptionAccountHealth {
|
|
|
134
158
|
private readonly records;
|
|
135
159
|
private readonly listeners;
|
|
136
160
|
private readonly anomalyListeners;
|
|
161
|
+
private readonly diagnostics;
|
|
137
162
|
private readonly now;
|
|
138
163
|
private overloadEnabled;
|
|
139
164
|
private overloadTtlMs;
|
|
@@ -150,14 +175,14 @@ declare class SubscriptionAccountHealth {
|
|
|
150
175
|
configure(opts: Pick<SubscriptionAccountHealthOptions, 'overloadEnabled' | 'overloadTtlMs' | 'authErrorTtlMs' | 'serverErrorTtlMs'>): void;
|
|
151
176
|
/**
|
|
152
177
|
* Whether an account may be scheduled RIGHT NOW. `blocked` → false; any timer
|
|
153
|
-
* still in the future → false. Expired timers are lazily deleted on read
|
|
154
|
-
*
|
|
178
|
+
* still in the future → false. Expired timers are lazily deleted on read so
|
|
179
|
+
* an elapsed cooldown restores the account WITHOUT a
|
|
155
180
|
* timer — but the recovery SIGNAL is the sweeper's job (`sweepRecoveries`), so
|
|
156
181
|
* this read never emits (correctness is independent of the tick).
|
|
157
182
|
*/
|
|
158
183
|
isSchedulable(providerId: string, accountId: string, now?: number): boolean;
|
|
159
184
|
/**
|
|
160
|
-
* The single marking entry point (design D3)
|
|
185
|
+
* The single marking entry point (design D3):
|
|
161
186
|
* - 429 + authoritative reset → `rateLimitEndAt`; a non-claude 429 may use
|
|
162
187
|
* `retryAfterSeconds`; a bare 429 (no resolvable reset) is NOT marked;
|
|
163
188
|
* - 529 → `overloadUntil` (gated by `overloadEnabled`);
|
|
@@ -194,6 +219,8 @@ declare class SubscriptionAccountHealth {
|
|
|
194
219
|
sweepRecoveries(now?: number): AccountRecoveryEvent[];
|
|
195
220
|
/** Admin-facing coarse status + cooldown-until for one account (secret-free). */
|
|
196
221
|
getStatus(providerId: string, accountId: string, now?: number): AccountHealthStatus;
|
|
222
|
+
/** Return newest-first, bounded, secret-free health edge diagnostics. */
|
|
223
|
+
getDiagnostics(filter?: AccountHealthDiagnosticFilter): AccountHealthDiagnostic[];
|
|
197
224
|
/**
|
|
198
225
|
* Register a recovery listener (the OQ3 seam #5 webhooks + #8 health-cron
|
|
199
226
|
* consume). Returns an unsubscribe function. Two edges fire it:
|
|
@@ -216,6 +243,7 @@ declare class SubscriptionAccountHealth {
|
|
|
216
243
|
*/
|
|
217
244
|
onAnomaly(listener: AccountAnomalyListener): () => void;
|
|
218
245
|
private emitAnomaly;
|
|
246
|
+
private recordDiagnostic;
|
|
219
247
|
/**
|
|
220
248
|
* Delete every EXPIRED timer field on the record in place; return whether any
|
|
221
249
|
* timer is STILL active (in the future). `blocked` is not a timer and is left
|
|
@@ -232,4 +260,4 @@ declare function setSharedAccountHealth(instance: SubscriptionAccountHealth): vo
|
|
|
232
260
|
/** Reset the shared singleton (tests / teardown only). */
|
|
233
261
|
declare function __resetSharedAccountHealthForTests(): void;
|
|
234
262
|
|
|
235
|
-
export { AUTH_ERROR_TTL_MS, type AccountAnomalyEvent, type AccountAnomalyListener, type AccountAnomalyState, type AccountHealthState, type AccountHealthStatus, type AccountRecoveryEvent, type AccountRecoveryListener, type HeadersLike, type HealthRecord, OVERLOAD_ENABLED_DEFAULT, OVERLOAD_TTL_MS, type RecordUpstreamOutcomeInput, SERVER_ERROR_TTL_MS, SubscriptionAccountHealth, type SubscriptionAccountHealthOptions, __resetSharedAccountHealthForTests, getSharedAccountHealth, resolveResetSeconds, setSharedAccountHealth };
|
|
263
|
+
export { ACCOUNT_HEALTH_DIAGNOSTIC_LIMIT, AUTH_ERROR_TTL_MS, type AccountAnomalyEvent, type AccountAnomalyListener, type AccountAnomalyState, type AccountHealthDiagnostic, type AccountHealthDiagnosticFilter, type AccountHealthState, type AccountHealthStatus, type AccountRecoveryEvent, type AccountRecoveryListener, type HeadersLike, type HealthRecord, OVERLOAD_ENABLED_DEFAULT, OVERLOAD_TTL_MS, type RecordUpstreamOutcomeInput, SERVER_ERROR_TTL_MS, SubscriptionAccountHealth, type SubscriptionAccountHealthOptions, __resetSharedAccountHealthForTests, getSharedAccountHealth, resolveResetSeconds, setSharedAccountHealth };
|