@wengine-ai/llms 2.3.2408 → 2.3.2409
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 +1 -1
- package/dist/cjs/server.cjs +88 -88
- package/dist/cjs/server.cjs.map +4 -4
- package/dist/esm/server.mjs +95 -95
- package/dist/esm/server.mjs.map +4 -4
- package/dist/index.html +11 -11
- package/dist/server.d.ts +2 -1
- package/dist/utils/concurrency-router.d.ts +91 -0
- package/package.json +2 -2
package/dist/server.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FastifyInstance, FastifyPluginAsync, FastifyPluginCallback, FastifyPluginOptions, FastifyRegisterOptions, preHandlerHookHandler, onRequestHookHandler, preParsingHookHandler, preValidationHookHandler, preSerializationHookHandler, onSendHookHandler, onResponseHookHandler, onTimeoutHookHandler, onErrorHookHandler, onRouteHookHandler, onRegisterHookHandler, onReadyHookHandler, onListenHookHandler, onCloseHookHandler, FastifyServerOptions } from "fastify";
|
|
1
|
+
import { FastifyInstance, FastifyPluginAsync, FastifyPluginCallback, FastifyPluginOptions, FastifyRegisterOptions, preHandlerHookHandler, onRequestHookHandler, preParsingHookHandler, preValidationHookHandler, preSerializationHookHandler, onSendHookHandler, onResponseHookHandler, onRequestAbortHookHandler, onTimeoutHookHandler, onErrorHookHandler, onRouteHookHandler, onRegisterHookHandler, onReadyHookHandler, onListenHookHandler, onCloseHookHandler, FastifyServerOptions } from "fastify";
|
|
2
2
|
import { ConfigService, AppConfig } from "./services/config";
|
|
3
3
|
import { ProviderService } from "./services/provider";
|
|
4
4
|
import { TransformerService } from "./services/transformer";
|
|
@@ -47,6 +47,7 @@ declare class Server {
|
|
|
47
47
|
addHook(hookName: "preSerialization", hookFunction: preSerializationHookHandler): void;
|
|
48
48
|
addHook(hookName: "onSend", hookFunction: onSendHookHandler): void;
|
|
49
49
|
addHook(hookName: "onResponse", hookFunction: onResponseHookHandler): void;
|
|
50
|
+
addHook(hookName: "onRequestAbort", hookFunction: onRequestAbortHookHandler): void;
|
|
50
51
|
addHook(hookName: "onTimeout", hookFunction: onTimeoutHookHandler): void;
|
|
51
52
|
addHook(hookName: "onError", hookFunction: onErrorHookHandler): void;
|
|
52
53
|
addHook(hookName: "onRoute", hookFunction: onRouteHookHandler): void;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Concurrency-Priority Routing
|
|
3
|
+
*
|
|
4
|
+
* When enabled (`Router.enableConcurrencyPriority`), this layers on top of the
|
|
5
|
+
* normal routing decision: whatever model the existing router selects (default,
|
|
6
|
+
* think, longContext, family default, ...) is checked against live in-flight
|
|
7
|
+
* concurrency:
|
|
8
|
+
*
|
|
9
|
+
* - A new (not yet pinned) session overflows to the least-loaded healthy model
|
|
10
|
+
* in the scenario-matching fallback list once the selected model's in-flight
|
|
11
|
+
* concurrency reaches `Router.concurrencyThreshold` (default 3).
|
|
12
|
+
* - Each session sticks to the first model it was assigned per routing slot
|
|
13
|
+
* (session + model family + scenario), which keeps provider-side prompt
|
|
14
|
+
* caches warm and avoids mid-session provider switches.
|
|
15
|
+
* - A session only changes models when its current model errors and the
|
|
16
|
+
* error-fallback path succeeds (routes.ts calls rebindSessionModel).
|
|
17
|
+
*
|
|
18
|
+
* All state is in-memory: bindings and in-flight leases are reset on restart,
|
|
19
|
+
* which is safe because a restart also drops all in-flight requests.
|
|
20
|
+
*/
|
|
21
|
+
export declare const DEFAULT_CONCURRENCY_THRESHOLD = 3;
|
|
22
|
+
interface Lease {
|
|
23
|
+
id: number;
|
|
24
|
+
key: string;
|
|
25
|
+
createdAt: number;
|
|
26
|
+
released: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface ConcurrencyPriorityDeps {
|
|
29
|
+
/**
|
|
30
|
+
* Resolve a "provider,model" route to its canonical form, or null when the
|
|
31
|
+
* target is unusable (missing, disabled, unhealthy, quota-exhausted). The
|
|
32
|
+
* caller injects router.ts's resolveConfiguredModel to avoid a module cycle.
|
|
33
|
+
*/
|
|
34
|
+
resolve: (modelKey: string) => string | null;
|
|
35
|
+
/** Ordered overflow candidates (the scenario-matching fallback lists). */
|
|
36
|
+
fallbackModels: string[];
|
|
37
|
+
/** Primary-model in-flight concurrency at which new sessions overflow. */
|
|
38
|
+
threshold: number;
|
|
39
|
+
log?: (msg: string) => void;
|
|
40
|
+
}
|
|
41
|
+
declare class ConcurrencyTracker {
|
|
42
|
+
private leases;
|
|
43
|
+
private nextId;
|
|
44
|
+
acquire(key: string): Lease;
|
|
45
|
+
release(lease: Lease | undefined | null): void;
|
|
46
|
+
private prune;
|
|
47
|
+
count(key: string): number;
|
|
48
|
+
clear(): void;
|
|
49
|
+
}
|
|
50
|
+
declare class SessionBindingStore {
|
|
51
|
+
private bindings;
|
|
52
|
+
get(sessionId: string): string | undefined;
|
|
53
|
+
bind(sessionId: string, modelKey: string): void;
|
|
54
|
+
unbind(sessionId: string): void;
|
|
55
|
+
clear(): void;
|
|
56
|
+
}
|
|
57
|
+
export declare function getConcurrencyTracker(): ConcurrencyTracker;
|
|
58
|
+
export declare function getSessionBindingStore(): SessionBindingStore;
|
|
59
|
+
/** Test helper: reset all concurrency-priority state. */
|
|
60
|
+
export declare function resetConcurrencyPriorityState(): void;
|
|
61
|
+
/**
|
|
62
|
+
* Stickiness slot key: bindings are tracked per session AND routing slot
|
|
63
|
+
* (model family + scenario), so a session can pin one model for its default
|
|
64
|
+
* traffic and another for think/longContext traffic without interfering.
|
|
65
|
+
*/
|
|
66
|
+
export declare function getRequestSlotKey(req: any): string;
|
|
67
|
+
/**
|
|
68
|
+
* Attach an in-flight lease for the given model key to the request. If the
|
|
69
|
+
* request already holds a lease for a different model (e.g. after a fallback
|
|
70
|
+
* switch), the old lease is released first so counts stay accurate.
|
|
71
|
+
*/
|
|
72
|
+
export declare function acquireRequestLease(req: any, key: string): void;
|
|
73
|
+
/** Release the request's in-flight lease (idempotent). */
|
|
74
|
+
export declare function releaseRequestLease(req: any): void;
|
|
75
|
+
/**
|
|
76
|
+
* Rebind the request's session to a new model after the error-fallback path
|
|
77
|
+
* succeeded with that model. No-op for requests that do not participate in
|
|
78
|
+
* concurrency-priority routing (no lease and no existing binding).
|
|
79
|
+
*/
|
|
80
|
+
export declare function rebindSessionModel(req: any, modelKey: string): void;
|
|
81
|
+
/**
|
|
82
|
+
* Apply concurrency-priority routing to a resolved default-scenario model.
|
|
83
|
+
*
|
|
84
|
+
* `currentModel` is the model the normal routing pipeline resolved for this
|
|
85
|
+
* request. The returned model is either the sticky bound model, an overflow
|
|
86
|
+
* fallback model, or `currentModel` unchanged. An in-flight lease for the
|
|
87
|
+
* returned model is attached to the request and must be released when the
|
|
88
|
+
* response completes (see request-pipeline.ts onResponse hook).
|
|
89
|
+
*/
|
|
90
|
+
export declare function routeWithConcurrencyPriority(req: any, currentModel: string, deps: ConcurrencyPriorityDeps): string;
|
|
91
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wengine-ai/llms",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.2409",
|
|
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.2409",
|
|
68
68
|
"adm-zip": "^0.5.16",
|
|
69
69
|
"better-sqlite3": "^12.10.0",
|
|
70
70
|
"rotating-file-stream": "^3.2.7"
|