@wengine-ai/llms 2.3.2427 → 2.3.2429
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/cjs/server.cjs +182 -182
- package/dist/cjs/server.cjs.map +4 -4
- package/dist/esm/server.mjs +182 -182
- package/dist/esm/server.mjs.map +4 -4
- package/dist/index.html +16 -16
- package/dist/provider-plugins/types.d.ts +35 -0
- package/dist/services/plugin-quota.d.ts +44 -0
- package/dist/services/provider-health.d.ts +6 -0
- package/dist/services/quota-store.d.ts +2 -0
- package/dist/transformer/anthropic.transformer.d.ts +1 -1
- package/package.json +2 -2
|
@@ -22,6 +22,31 @@ export interface PluginManifest {
|
|
|
22
22
|
coreApi: string;
|
|
23
23
|
description?: string;
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Quota figures reported by a managed runtime's `fetchQuota` seam.
|
|
27
|
+
*
|
|
28
|
+
* The field family mirrors `ProviderQuotaResult` in services/quota-adapters so a
|
|
29
|
+
* plugin sample flows through the SAME storage and 5h/7d UI mapping as the
|
|
30
|
+
* built-in quota adapters: the daily fields feed the short (5h) window while
|
|
31
|
+
* the balance fields feed the 7d window. All fields are optional — a runtime
|
|
32
|
+
* reports whichever figures its subscription endpoint exposes.
|
|
33
|
+
*/
|
|
34
|
+
export interface ProviderQuotaFigures {
|
|
35
|
+
/** Spend/usage inside the current short (daily/5h) window. */
|
|
36
|
+
usedDailyBalance?: number;
|
|
37
|
+
/** Explicit limit for the short window, when the endpoint exposes one. */
|
|
38
|
+
limitDaily?: number;
|
|
39
|
+
/** ISO timestamp at which the short window resets. */
|
|
40
|
+
resetTime?: string;
|
|
41
|
+
/** Spend inside the 7d/weekly balance window. */
|
|
42
|
+
usedBalance?: number;
|
|
43
|
+
/** Total balance/limit for the 7d window. */
|
|
44
|
+
totalBalance?: number;
|
|
45
|
+
/** ISO timestamp at which the 7d window resets. */
|
|
46
|
+
resetTime7d?: string;
|
|
47
|
+
/** Currency code; when absent the UI renders the figures as rate-limit units. */
|
|
48
|
+
currency?: string;
|
|
49
|
+
}
|
|
25
50
|
/** A classified upstream error, shared shape across providers (contract §1.6). */
|
|
26
51
|
export interface PluginClassifiedError {
|
|
27
52
|
code: string;
|
|
@@ -163,6 +188,16 @@ export interface ManagedRuntime {
|
|
|
163
188
|
* `dispatchRequest` (see `PluginDispatchInput`).
|
|
164
189
|
*/
|
|
165
190
|
probeLiveness?(input: ManagedProbeInput): Promise<Response>;
|
|
191
|
+
/**
|
|
192
|
+
* Optional quota probe for the subscription account. The core polls it from
|
|
193
|
+
* the same quota-probe loop as the built-in adapters and merges the result
|
|
194
|
+
* into /api/providers/quota through the shared quota store. Calls are
|
|
195
|
+
* TTL-cached per provider name (60s), so a runtime may implement this as a
|
|
196
|
+
* plain authenticated fetch without its own throttling. Return null (or
|
|
197
|
+
* reject) when no figures are available — the core treats that as "no data",
|
|
198
|
+
* never as a request failure.
|
|
199
|
+
*/
|
|
200
|
+
fetchQuota?(provider: LLMProvider): Promise<ProviderQuotaFigures | null>;
|
|
166
201
|
/**
|
|
167
202
|
* Opt-in 401 handling: when set, the core performs ONE forced refresh and
|
|
168
203
|
* re-dispatch on 401 before classifying. `refresh` must persist rotated
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TTL-cached polling of the managed-runtime `fetchQuota` seam.
|
|
3
|
+
*
|
|
4
|
+
* Managed subscription plugins own authenticated quota endpoints (e.g. the
|
|
5
|
+
* Gemini OAuth billing API). The core must not hit such an endpoint on every
|
|
6
|
+
* UI refresh of /api/providers/quota, so each provider name keeps one entry
|
|
7
|
+
* refreshed at most once per PLUGIN_QUOTA_TTL_MS. The cache is in-memory only:
|
|
8
|
+
* quota figures are transient, and the periodic active-probe loop repopulates
|
|
9
|
+
* it after a restart.
|
|
10
|
+
*
|
|
11
|
+
* The polling result is handed to the shared quota store, which makes the
|
|
12
|
+
* plugin seam a single data source alongside the built-in quota adapters —
|
|
13
|
+
* the admin route's existing stored-result merge is the only read path.
|
|
14
|
+
*/
|
|
15
|
+
import type { ProviderQuotaFigures } from "../provider-plugins/types";
|
|
16
|
+
import type { LLMProvider } from "../types/llm";
|
|
17
|
+
/** Per-provider refresh interval for the plugin quota seam. */
|
|
18
|
+
export declare const PLUGIN_QUOTA_TTL_MS = 60000;
|
|
19
|
+
/**
|
|
20
|
+
* Upper bound the /api/providers/quota route waits for an on-demand plugin
|
|
21
|
+
* poll. A blackholed proxy must not hang the admin endpoint: when the budget
|
|
22
|
+
* elapses the route serves the stored figures and the in-flight poll still
|
|
23
|
+
* lands in the store for the next request.
|
|
24
|
+
*/
|
|
25
|
+
export declare const PLUGIN_QUOTA_INLINE_BUDGET_MS = 2500;
|
|
26
|
+
/** Test-only: drop every cached entry so timings stay deterministic. */
|
|
27
|
+
export declare function resetPluginQuotaCache(): void;
|
|
28
|
+
/** Whether the provider's entry is still inside its TTL window. */
|
|
29
|
+
export declare function hasFreshPluginQuota(providerName: string, now?: number): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Poll a managed runtime's quota seam for one provider.
|
|
32
|
+
*
|
|
33
|
+
* Behaviour contract:
|
|
34
|
+
* - an in-flight poll is joined instead of duplicated, and a fresh TTL entry
|
|
35
|
+
* resolves without another upstream call;
|
|
36
|
+
* - a figures result is written through the shared quota store, so the admin
|
|
37
|
+
* route's 5h/7d mapping applies unchanged;
|
|
38
|
+
* - a null result or a rejected seam call means "no data" — the entry is
|
|
39
|
+
* still stamped so the TTL backs off retries, and the error never escapes
|
|
40
|
+
* into the response path.
|
|
41
|
+
*/
|
|
42
|
+
export declare function pollPluginQuota(providerName: string, provider: LLMProvider, runtime: {
|
|
43
|
+
fetchQuota?(provider: LLMProvider): Promise<ProviderQuotaFigures | null>;
|
|
44
|
+
}): Promise<void>;
|
|
@@ -8,6 +8,12 @@ export interface ProviderHealthState {
|
|
|
8
8
|
failureCount: number;
|
|
9
9
|
successCount: number;
|
|
10
10
|
lastFailureTime: number;
|
|
11
|
+
/** Epoch ms of the last recorded successful request. Optional so states and
|
|
12
|
+
* persisted files written before this field stay valid. The UI uses
|
|
13
|
+
* `lastFailureTime && (!lastSuccessTime || lastFailureTime > lastSuccessTime)`
|
|
14
|
+
* to tell a stale failure (a later success already recovered the model)
|
|
15
|
+
* from a still-active one. */
|
|
16
|
+
lastSuccessTime?: number;
|
|
11
17
|
lastProbeTime: number;
|
|
12
18
|
lastError?: string;
|
|
13
19
|
/** Epoch ms before which a rate-limited model should NOT be probed or used.
|
|
@@ -6,6 +6,8 @@ export interface StoredQuotaResult extends ProviderQuotaResult {
|
|
|
6
6
|
export declare function storeQuotaResult(providerName: string, result: ProviderQuotaResult): void;
|
|
7
7
|
export declare function getQuotaResult(providerName: string): StoredQuotaResult | undefined;
|
|
8
8
|
export declare function getAllQuotaResults(): StoredQuotaResult[];
|
|
9
|
+
/** Test-only: drop every in-memory quota sample so stores stay isolated. */
|
|
10
|
+
export declare function clearQuotaStore(): void;
|
|
9
11
|
/**
|
|
10
12
|
* Initialize persistence: load from disk and set up periodic save.
|
|
11
13
|
*/
|
|
@@ -8,7 +8,7 @@ export declare class AnthropicTransformer implements Transformer {
|
|
|
8
8
|
logger?: any;
|
|
9
9
|
constructor(options?: TransformerOptions | undefined);
|
|
10
10
|
auth(request: any, provider: LLMProvider): Promise<any>;
|
|
11
|
-
transformRequestOut(request:
|
|
11
|
+
transformRequestOut(request: any): Promise<UnifiedChatRequest>;
|
|
12
12
|
transformRequestIn(request: UnifiedChatRequest, provider: LLMProvider, context: TransformerContext): Promise<any>;
|
|
13
13
|
private isAnthropicMessagesEndpoint;
|
|
14
14
|
transformResponseIn(response: Response, context?: TransformerContext): Promise<Response>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wengine-ai/llms",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.2429",
|
|
4
4
|
"description": "A universal LLM API transformation server",
|
|
5
5
|
"main": "dist/cjs/server.cjs",
|
|
6
6
|
"module": "dist/esm/server.mjs",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"uuid": "^11.1.0",
|
|
65
65
|
"@fastify/multipart": "^9.0.0",
|
|
66
66
|
"@fastify/static": "^8.2.0",
|
|
67
|
-
"@wengine-ai/claude-code-router-shared": "^2.3.
|
|
67
|
+
"@wengine-ai/claude-code-router-shared": "^2.3.2429",
|
|
68
68
|
"adm-zip": "^0.5.16",
|
|
69
69
|
"better-sqlite3": "^12.10.0",
|
|
70
70
|
"rotating-file-stream": "^3.2.7"
|