@wengine-ai/llms 2.3.231 → 2.3.234
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 +10 -5
- package/dist/api/middleware.d.ts +9 -0
- package/dist/api/routes.d.ts +24 -0
- package/dist/ccr/admin-routes.d.ts +6 -0
- package/dist/ccr/agents/image.agent.d.ts +10 -0
- package/dist/ccr/agents/index.d.ts +28 -0
- package/dist/ccr/agents/type.d.ts +13 -0
- package/dist/ccr/auth.d.ts +8 -0
- package/dist/ccr/claude-config-init.d.ts +1 -0
- package/dist/ccr/codex-accounts.d.ts +9 -0
- package/dist/ccr/codex-usage-cache.d.ts +2 -0
- package/dist/ccr/config.d.ts +6 -0
- package/dist/ccr/create-server.d.ts +6 -0
- package/dist/ccr/health-reconcile.d.ts +22 -0
- package/dist/ccr/models.d.ts +26 -0
- package/dist/ccr/pino-retention.d.ts +1 -0
- package/dist/ccr/plugin-registration.d.ts +6 -0
- package/dist/ccr/request-pipeline.d.ts +37 -0
- package/dist/ccr/usage-merge.d.ts +32 -0
- package/dist/ccr/usage-store.d.ts +109 -0
- package/dist/cjs/server.cjs +337 -350
- package/dist/cjs/server.cjs.map +4 -4
- package/dist/clients/adapters.d.ts +22 -0
- package/dist/esm/server.mjs +338 -350
- package/dist/esm/server.mjs.map +4 -4
- package/dist/index.html +227 -0
- package/dist/plugins/index.d.ts +4 -0
- package/dist/plugins/output/console-handler.d.ts +23 -0
- package/dist/plugins/output/index.d.ts +29 -0
- package/dist/plugins/output/output-manager.d.ts +108 -0
- package/dist/plugins/output/temp-file-handler.d.ts +48 -0
- package/dist/plugins/output/types.d.ts +157 -0
- package/dist/plugins/output/webhook-handler.d.ts +35 -0
- package/dist/plugins/plugin-manager.d.ts +62 -0
- package/dist/plugins/token-speed.d.ts +5 -0
- package/dist/plugins/types.d.ts +25 -0
- package/dist/server.d.ts +110 -0
- package/dist/services/active-probe.d.ts +96 -0
- package/dist/services/config.d.ts +30 -0
- package/dist/services/provider-health.d.ts +135 -0
- package/dist/services/provider.d.ts +32 -0
- package/dist/services/proxy.d.ts +58 -0
- package/dist/services/quota-adapters.d.ts +16 -0
- package/dist/services/quota-store.d.ts +12 -0
- package/dist/services/rate-limit.d.ts +26 -0
- package/dist/services/tokenizer.d.ts +45 -0
- package/dist/services/transformer.d.ts +28 -0
- package/dist/tiktoken_bg.wasm +0 -0
- package/dist/tokenizer/api-tokenizer.d.ts +46 -0
- package/dist/tokenizer/huggingface-tokenizer.d.ts +52 -0
- package/dist/tokenizer/tiktoken-tokenizer.d.ts +20 -0
- package/dist/transformer/anthropic.transformer.d.ts +18 -0
- package/dist/transformer/cerebras.transformer.d.ts +16 -0
- package/dist/transformer/cleancache.transformer.d.ts +6 -0
- package/dist/transformer/customparams.transformer.d.ts +30 -0
- package/dist/transformer/deepseek.transformer.d.ts +7 -0
- package/dist/transformer/enhancetool.transformer.d.ts +5 -0
- package/dist/transformer/forcereasoning.transformer.d.ts +7 -0
- package/dist/transformer/gemini.transformer.d.ts +10 -0
- package/dist/transformer/groq.transformer.d.ts +7 -0
- package/dist/transformer/index.d.ts +49 -0
- package/dist/transformer/kimi.transformer.d.ts +17 -0
- package/dist/transformer/maxcompletiontokens.transformer.d.ts +6 -0
- package/dist/transformer/maxtoken.transformer.d.ts +9 -0
- package/dist/transformer/openai.responses.transformer.d.ts +28 -0
- package/dist/transformer/openai.transformer.d.ts +5 -0
- package/dist/transformer/opencode.transformer.d.ts +29 -0
- package/dist/transformer/openrouter.transformer.d.ts +9 -0
- package/dist/transformer/reasoning.transformer.d.ts +10 -0
- package/dist/transformer/sampling.transformer.d.ts +13 -0
- package/dist/transformer/streamoptions.transformer.d.ts +6 -0
- package/dist/transformer/tooluse.transformer.d.ts +7 -0
- package/dist/transformer/vercel.transformer.d.ts +10 -0
- package/dist/transformer/vertex-claude.transformer.d.ts +8 -0
- package/dist/transformer/vertex-gemini.transformer.d.ts +8 -0
- package/dist/types/llm.d.ts +233 -0
- package/dist/types/transformer.d.ts +23 -0
- package/dist/utils/cache.d.ts +17 -0
- package/dist/utils/converter.d.ts +12 -0
- package/dist/utils/debug-log.d.ts +24 -0
- package/dist/utils/fallback-promotion.d.ts +65 -0
- package/dist/utils/gemini.util.d.ts +11 -0
- package/dist/utils/image.d.ts +1 -0
- package/dist/utils/request.d.ts +2 -0
- package/dist/utils/router.d.ts +84 -0
- package/dist/utils/session-id.d.ts +2 -0
- package/dist/utils/sse/SSEParser.transform.d.ts +6 -0
- package/dist/utils/sse/SSESerializer.transform.d.ts +3 -0
- package/dist/utils/sse/index.d.ts +3 -0
- package/dist/utils/sse/rewriteStream.d.ts +9 -0
- package/dist/utils/thinking.d.ts +2 -0
- package/dist/utils/toolArgumentsParser.d.ts +8 -0
- package/dist/utils/vertex-claude.util.d.ts +42 -0
- package/package.json +13 -6
- package/vitest.config.ts +1 -0
- package/dist/index.d.ts +0 -175
- package/dist/plugins.d.ts +0 -42
- package/dist/provider-health.d.ts +0 -39
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fallback Promotion Cache
|
|
3
|
+
*
|
|
4
|
+
* When a primary model fails and fallback succeeds, we "promote" the fallback model
|
|
5
|
+
* so subsequent requests skip the failing primary entirely until TTL expires or
|
|
6
|
+
* the promoted model becomes unhealthy.
|
|
7
|
+
*/
|
|
8
|
+
export interface FallbackPromotionConfig {
|
|
9
|
+
enabled?: boolean;
|
|
10
|
+
ttlMinutes?: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Fallback Promotion Store
|
|
14
|
+
* Tracks successful fallback promotions to avoid retrying failing primaries
|
|
15
|
+
*/
|
|
16
|
+
declare class FallbackPromotionStore {
|
|
17
|
+
private promotions;
|
|
18
|
+
private enabled;
|
|
19
|
+
private ttlMs;
|
|
20
|
+
configure(config?: FallbackPromotionConfig): void;
|
|
21
|
+
/**
|
|
22
|
+
* Generate a cache key for a primary model
|
|
23
|
+
* Format: ${provider},${model}:${scenarioType}
|
|
24
|
+
*/
|
|
25
|
+
private getKey;
|
|
26
|
+
/**
|
|
27
|
+
* Promote a fallback model for a failing primary
|
|
28
|
+
* After this, all clients will use the promoted model until TTL expires
|
|
29
|
+
*/
|
|
30
|
+
promote(provider: string, model: string, scenarioType: string, fallbackProvider: string, fallbackModel: string, ttlMs?: number): void;
|
|
31
|
+
/**
|
|
32
|
+
* Get the promoted model for a primary, if one exists and is valid
|
|
33
|
+
* Returns null if: disabled, no promotion, expired, or promoted model unhealthy
|
|
34
|
+
*/
|
|
35
|
+
getPromotion(provider: string, model: string, scenarioType: string, providers: any[]): string | null;
|
|
36
|
+
/**
|
|
37
|
+
* Clear a specific promotion
|
|
38
|
+
*/
|
|
39
|
+
clear(provider: string, model: string, scenarioType: string): void;
|
|
40
|
+
/**
|
|
41
|
+
* Clear all promotions for a specific primary model
|
|
42
|
+
* Called when a model recovers to closed (healthy) state
|
|
43
|
+
* @returns number of promotions cleared
|
|
44
|
+
*/
|
|
45
|
+
clearByPrimary(provider: string, model: string): number;
|
|
46
|
+
/**
|
|
47
|
+
* Clear all promotions
|
|
48
|
+
*/
|
|
49
|
+
clearAll(): void;
|
|
50
|
+
/**
|
|
51
|
+
* Clear expired promotions (cleanup utility)
|
|
52
|
+
*/
|
|
53
|
+
clearExpired(): void;
|
|
54
|
+
/**
|
|
55
|
+
* Get all active promotions (for debugging/monitoring)
|
|
56
|
+
*/
|
|
57
|
+
getAllPromotions(): Array<{
|
|
58
|
+
key: string;
|
|
59
|
+
promotedModel: string;
|
|
60
|
+
remainingMs: number;
|
|
61
|
+
}>;
|
|
62
|
+
}
|
|
63
|
+
export declare function getFallbackPromotionStore(config?: FallbackPromotionConfig): FallbackPromotionStore;
|
|
64
|
+
export declare function resetFallbackPromotionStore(): void;
|
|
65
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { UnifiedChatRequest } from "../types/llm";
|
|
2
|
+
export declare function cleanupParameters(obj: any, keyName?: string): void;
|
|
3
|
+
/**
|
|
4
|
+
* Transform a tool object
|
|
5
|
+
* @param {Object} tool - The tool object to transform
|
|
6
|
+
* @returns {Object} - The transformed tool object
|
|
7
|
+
*/
|
|
8
|
+
export declare function tTool(tool: any): any;
|
|
9
|
+
export declare function buildRequestBody(request: UnifiedChatRequest): Record<string, any>;
|
|
10
|
+
export declare function transformRequestOut(request: Record<string, any>): UnifiedChatRequest;
|
|
11
|
+
export declare function transformResponseOut(response: Response, providerName: string, logger?: any): Promise<Response>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const formatBase64: (data: string, media_type: string) => string;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Usage } from "./cache";
|
|
2
|
+
import { ConfigService } from "../services/config";
|
|
3
|
+
import { TokenizerService } from "../services/tokenizer";
|
|
4
|
+
import { type ClientContext } from "../clients/adapters";
|
|
5
|
+
export declare class ProjectRoutingError extends Error {
|
|
6
|
+
statusCode: number;
|
|
7
|
+
code: string;
|
|
8
|
+
type: string;
|
|
9
|
+
sessionId?: string;
|
|
10
|
+
configuredTarget?: string;
|
|
11
|
+
constructor(message: string, opts?: {
|
|
12
|
+
sessionId?: string;
|
|
13
|
+
configuredTarget?: string;
|
|
14
|
+
code?: string;
|
|
15
|
+
statusCode?: number;
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
interface Tool {
|
|
19
|
+
name: string;
|
|
20
|
+
description?: string;
|
|
21
|
+
input_schema: object;
|
|
22
|
+
}
|
|
23
|
+
interface ContentBlockParam {
|
|
24
|
+
type: string;
|
|
25
|
+
[key: string]: any;
|
|
26
|
+
}
|
|
27
|
+
interface MessageParam {
|
|
28
|
+
role: string;
|
|
29
|
+
content: string | ContentBlockParam[];
|
|
30
|
+
}
|
|
31
|
+
export declare const calculateTokenCount: (messages: MessageParam[], system: any, tools: Tool[]) => number;
|
|
32
|
+
/**
|
|
33
|
+
* Look up a provider and model by name in the current provider list.
|
|
34
|
+
* Returns canonical (case-matched) values or null when the provider is
|
|
35
|
+
* missing, disabled, or the model is not listed under it.
|
|
36
|
+
*/
|
|
37
|
+
export declare function findProviderModel(providers: any[], providerName: string, modelName: string): {
|
|
38
|
+
provider: any;
|
|
39
|
+
model: string;
|
|
40
|
+
} | null;
|
|
41
|
+
/**
|
|
42
|
+
* Diagnose why a "provider,model" route string fails to resolve.
|
|
43
|
+
* Returns a human-readable reason and a stable error code so the
|
|
44
|
+
* ProjectRoutingError can carry actionable diagnostic info.
|
|
45
|
+
*/
|
|
46
|
+
export declare function diagnoseResolutionFailure(configuredModel: string, providers: any[]): {
|
|
47
|
+
reason: string;
|
|
48
|
+
code: string;
|
|
49
|
+
};
|
|
50
|
+
interface RouterFamilyConfig {
|
|
51
|
+
default: string;
|
|
52
|
+
background?: string;
|
|
53
|
+
think?: string;
|
|
54
|
+
longContext?: string;
|
|
55
|
+
longContextThreshold?: number;
|
|
56
|
+
extendedContext?: string;
|
|
57
|
+
extendedContextThreshold?: number;
|
|
58
|
+
enableExtendedContext?: boolean;
|
|
59
|
+
webSearch?: string;
|
|
60
|
+
image?: string;
|
|
61
|
+
fallback?: Record<string, string[]>;
|
|
62
|
+
}
|
|
63
|
+
export declare function getEffectiveTokenCount(tokenCount: number, lastUsage: Usage | undefined, clientContext?: ClientContext): number;
|
|
64
|
+
export declare function getExtendedContextThreshold(clientContext: ClientContext | undefined, familyConfig?: RouterFamilyConfig, globalExtendedContextThreshold?: number): number;
|
|
65
|
+
export interface RouterContext {
|
|
66
|
+
configService: ConfigService;
|
|
67
|
+
tokenizerService?: TokenizerService;
|
|
68
|
+
event?: any;
|
|
69
|
+
}
|
|
70
|
+
export type RouterScenarioType = 'default' | 'background' | 'think' | 'longContext' | 'extendedContext' | 'webSearch' | 'modelMapping' | 'image';
|
|
71
|
+
export interface RouterFallbackConfig {
|
|
72
|
+
[key: string]: string[] | undefined;
|
|
73
|
+
default?: string[];
|
|
74
|
+
background?: string[];
|
|
75
|
+
think?: string[];
|
|
76
|
+
longContext?: string[];
|
|
77
|
+
extendedContext?: string[];
|
|
78
|
+
webSearch?: string[];
|
|
79
|
+
modelMapping?: string[];
|
|
80
|
+
image?: string[];
|
|
81
|
+
}
|
|
82
|
+
export declare const router: (req: any, _res: any, context: RouterContext) => Promise<void>;
|
|
83
|
+
export declare const searchProjectBySession: (sessionId: string) => Promise<string | null>;
|
|
84
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rewrite stream utility
|
|
3
|
+
* Reads source readablestream and returns a new readablestream,
|
|
4
|
+
* processor processes source data and pushes returned new value to new stream,
|
|
5
|
+
* no push if no return value
|
|
6
|
+
* @param stream
|
|
7
|
+
* @param processor
|
|
8
|
+
*/
|
|
9
|
+
export declare const rewriteStream: (stream: ReadableStream, processor: (data: any, controller: ReadableStreamController<any>) => Promise<any>) => ReadableStream;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse tool call arguments function
|
|
3
|
+
* First try standard JSON parsing, then JSON5 parsing, finally use jsonrepair for safe repair
|
|
4
|
+
*
|
|
5
|
+
* @param argsString - Parameter string to parse
|
|
6
|
+
* @returns Parsed parameter object or safe empty object
|
|
7
|
+
*/
|
|
8
|
+
export declare function parseToolArguments(argsString: string, logger?: any): string;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { UnifiedChatRequest } from "../types/llm";
|
|
2
|
+
interface ClaudeMessage {
|
|
3
|
+
role: "user" | "assistant";
|
|
4
|
+
content: Array<{
|
|
5
|
+
type: "text" | "image";
|
|
6
|
+
text?: string;
|
|
7
|
+
source?: {
|
|
8
|
+
type: "base64";
|
|
9
|
+
media_type: string;
|
|
10
|
+
data: string;
|
|
11
|
+
};
|
|
12
|
+
}>;
|
|
13
|
+
}
|
|
14
|
+
interface ClaudeTool {
|
|
15
|
+
name: string;
|
|
16
|
+
description: string;
|
|
17
|
+
input_schema: {
|
|
18
|
+
type: string;
|
|
19
|
+
properties: Record<string, any>;
|
|
20
|
+
required?: string[];
|
|
21
|
+
additionalProperties?: boolean;
|
|
22
|
+
$schema?: string;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
interface VertexClaudeRequest {
|
|
26
|
+
anthropic_version: "vertex-2023-10-16";
|
|
27
|
+
messages: ClaudeMessage[];
|
|
28
|
+
max_tokens: number;
|
|
29
|
+
stream?: boolean;
|
|
30
|
+
temperature?: number;
|
|
31
|
+
top_p?: number;
|
|
32
|
+
top_k?: number;
|
|
33
|
+
tools?: ClaudeTool[];
|
|
34
|
+
tool_choice?: "auto" | "none" | {
|
|
35
|
+
type: "tool";
|
|
36
|
+
name: string;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export declare function buildRequestBody(request: UnifiedChatRequest): VertexClaudeRequest;
|
|
40
|
+
export declare function transformRequestOut(request: Record<string, any>): UnifiedChatRequest;
|
|
41
|
+
export declare function transformResponseOut(response: Response, providerName: string, logger?: any): Promise<Response>;
|
|
42
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wengine-ai/llms",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.234",
|
|
4
4
|
"description": "A universal LLM API transformation server",
|
|
5
5
|
"main": "dist/cjs/server.cjs",
|
|
6
6
|
"module": "dist/esm/server.mjs",
|
|
7
|
-
"types": "./dist/
|
|
7
|
+
"types": "./dist/server.d.ts",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
-
"types": "./dist/
|
|
11
|
+
"types": "./dist/server.d.ts",
|
|
12
12
|
"import": "./dist/esm/server.mjs",
|
|
13
13
|
"require": "./dist/cjs/server.cjs"
|
|
14
14
|
}
|
|
@@ -49,14 +49,21 @@
|
|
|
49
49
|
"openai": "^5.6.0",
|
|
50
50
|
"tiktoken": "^1.0.21",
|
|
51
51
|
"undici": "^7.10.0",
|
|
52
|
-
"uuid": "^11.1.0"
|
|
52
|
+
"uuid": "^11.1.0",
|
|
53
|
+
"@fastify/multipart": "^9.0.0",
|
|
54
|
+
"@fastify/static": "^8.2.0",
|
|
55
|
+
"@wengine-ai/claude-code-router-shared": "workspace:*",
|
|
56
|
+
"adm-zip": "^0.5.16",
|
|
57
|
+
"better-sqlite3": "^12.10.0",
|
|
58
|
+
"rotating-file-stream": "^3.2.7"
|
|
53
59
|
},
|
|
54
60
|
"devDependencies": {
|
|
55
61
|
"@types/node": "^24.0.15",
|
|
56
|
-
"@wengine-ai/claude-code-router-shared": "workspace:*",
|
|
57
62
|
"esbuild": "^0.25.1",
|
|
58
63
|
"tsx": "^4.20.3",
|
|
59
64
|
"typescript": "^5.8.2",
|
|
60
|
-
"vitest": "^4.1.9"
|
|
65
|
+
"vitest": "^4.1.9",
|
|
66
|
+
"@types/adm-zip": "^0.5.7",
|
|
67
|
+
"@types/better-sqlite3": "^7.6.13"
|
|
61
68
|
}
|
|
62
69
|
}
|
package/vitest.config.ts
CHANGED
package/dist/index.d.ts
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
// Main type declarations for @wengine-ai/llms
|
|
2
|
-
|
|
3
|
-
// Re-export plugin declarations (pluginManager, tokenSpeedPlugin, etc.)
|
|
4
|
-
export * from "./plugins";
|
|
5
|
-
|
|
6
|
-
// Health store types
|
|
7
|
-
export interface ProviderHealthState {
|
|
8
|
-
provider: string;
|
|
9
|
-
model: string;
|
|
10
|
-
status: 'closed' | 'open' | 'half-open';
|
|
11
|
-
failureCount: number;
|
|
12
|
-
successCount: number;
|
|
13
|
-
lastFailureTime: number;
|
|
14
|
-
lastProbeTime: number;
|
|
15
|
-
lastError?: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface HealthPoolConfig {
|
|
19
|
-
enabled?: boolean;
|
|
20
|
-
failureThreshold?: number;
|
|
21
|
-
probeIntervalMinutes?: number;
|
|
22
|
-
halfOpenSuccessThreshold?: number;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export class ProviderHealthStore {
|
|
26
|
-
constructor(config?: HealthPoolConfig);
|
|
27
|
-
recordSuccess(provider: string, model: string): void;
|
|
28
|
-
recordFailure(provider: string, model: string, error?: string): void;
|
|
29
|
-
getState(provider: string, model: string): ProviderHealthState | undefined;
|
|
30
|
-
isAvailable(provider: string, model: string): boolean;
|
|
31
|
-
getPriority(provider: string, model: string): number;
|
|
32
|
-
needsProbe(state: ProviderHealthState): boolean;
|
|
33
|
-
markProbeAttempt(provider: string, model: string): void;
|
|
34
|
-
clear(): void;
|
|
35
|
-
getAllStates(): ProviderHealthState[];
|
|
36
|
-
getFailPoolModels(): string[];
|
|
37
|
-
getHalfOpenModels(): string[];
|
|
38
|
-
stopProbeTimer(): void;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export declare function getHealthStore(config?: HealthPoolConfig): ProviderHealthStore;
|
|
42
|
-
export declare function resetHealthStore(): void;
|
|
43
|
-
|
|
44
|
-
// Core exports
|
|
45
|
-
export interface RouterScenarioType {
|
|
46
|
-
'default': 'default';
|
|
47
|
-
'background': 'background';
|
|
48
|
-
'think': 'think';
|
|
49
|
-
'longContext': 'longContext';
|
|
50
|
-
'extendedContext': 'extendedContext';
|
|
51
|
-
'webSearch': 'webSearch';
|
|
52
|
-
'modelMapping': 'modelMapping';
|
|
53
|
-
'image': 'image';
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export interface RouterFallbackConfig {
|
|
57
|
-
default?: string[];
|
|
58
|
-
background?: string[];
|
|
59
|
-
think?: string[];
|
|
60
|
-
longContext?: string[];
|
|
61
|
-
webSearch?: string[];
|
|
62
|
-
modelMapping?: string[];
|
|
63
|
-
image?: string[];
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export class ConfigService {
|
|
67
|
-
get<T>(key: string): T | undefined;
|
|
68
|
-
getAll(): Record<string, any>;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export class ProviderService {
|
|
72
|
-
getProvider(name: string): any | undefined;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export class TransformerService {
|
|
76
|
-
getTransformersWithEndpoint(): Array<{ transformer: any }>;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export class TokenizerService {
|
|
80
|
-
countTokens(request: any, config?: any): Promise<{ tokenCount: number }>;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export function router(req: any, reply: any, context: any): Promise<void>;
|
|
84
|
-
export function calculateTokenCount(messages: any[], system: any, tools: any[]): number;
|
|
85
|
-
export function searchProjectBySession(sessionId: string): Promise<string | null>;
|
|
86
|
-
|
|
87
|
-
// Session cache
|
|
88
|
-
export const sessionUsageCache: any;
|
|
89
|
-
|
|
90
|
-
// SSE utilities
|
|
91
|
-
export class SSEParserTransform {}
|
|
92
|
-
export class SSESerializerTransform {}
|
|
93
|
-
export function rewriteStream(stream: any, handler: any): any;
|
|
94
|
-
|
|
95
|
-
// Rate limit types
|
|
96
|
-
export interface RateLimitInfo {
|
|
97
|
-
provider: string;
|
|
98
|
-
remaining: number | null;
|
|
99
|
-
limit: number | null;
|
|
100
|
-
reset: number | null;
|
|
101
|
-
capturedAt: number;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export declare function getAllRateLimitInfo(): RateLimitInfo[];
|
|
105
|
-
export declare function getRateLimitInfo(providerName: string): RateLimitInfo | undefined;
|
|
106
|
-
export declare function initRateLimitPersistence(): void;
|
|
107
|
-
|
|
108
|
-
// Active probe types
|
|
109
|
-
export interface ActiveProbeConfig {
|
|
110
|
-
enabled?: boolean;
|
|
111
|
-
quotaProbeIntervalMinutes?: number;
|
|
112
|
-
probeTimeoutMs?: number;
|
|
113
|
-
initialDelayMs?: number;
|
|
114
|
-
excludeProviders?: string[];
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export interface LLMProvider {
|
|
118
|
-
name: string;
|
|
119
|
-
baseUrl: string;
|
|
120
|
-
apiKey: string;
|
|
121
|
-
models: string[];
|
|
122
|
-
transformer?: any;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export class ActiveProbeService {
|
|
126
|
-
constructor(
|
|
127
|
-
getProviders: () => LLMProvider[],
|
|
128
|
-
config?: ActiveProbeConfig,
|
|
129
|
-
getHttpsProxy?: () => string | undefined,
|
|
130
|
-
logger?: any
|
|
131
|
-
);
|
|
132
|
-
start(): void;
|
|
133
|
-
stop(): void;
|
|
134
|
-
probeProviderManually(providerName: string): Promise<boolean>;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export declare function getActiveProbeService(
|
|
138
|
-
getProviders: () => LLMProvider[],
|
|
139
|
-
config?: ActiveProbeConfig,
|
|
140
|
-
getHttpsProxy?: () => string | undefined,
|
|
141
|
-
logger?: any
|
|
142
|
-
): ActiveProbeService;
|
|
143
|
-
|
|
144
|
-
export declare function startActiveProbe(
|
|
145
|
-
getProviders: () => LLMProvider[],
|
|
146
|
-
config?: ActiveProbeConfig,
|
|
147
|
-
getHttpsProxy?: () => string | undefined,
|
|
148
|
-
logger?: any
|
|
149
|
-
): ActiveProbeService;
|
|
150
|
-
|
|
151
|
-
export declare function stopActiveProbe(): void;
|
|
152
|
-
export declare function resetActiveProbeService(): void;
|
|
153
|
-
|
|
154
|
-
// Runtime debug log toggle
|
|
155
|
-
export declare function setRuntimeDebugLog(enabled: boolean): void;
|
|
156
|
-
export declare function getRuntimeDebugLog(): boolean;
|
|
157
|
-
|
|
158
|
-
// Quota
|
|
159
|
-
export interface QuotaAdapter {
|
|
160
|
-
checkQuota(providerName: string, model: string): Promise<boolean>;
|
|
161
|
-
}
|
|
162
|
-
export interface ProviderQuotaResult {
|
|
163
|
-
totalBalance?: number;
|
|
164
|
-
usedBalance?: number;
|
|
165
|
-
limitDaily?: number;
|
|
166
|
-
usedDailyBalance?: number;
|
|
167
|
-
}
|
|
168
|
-
export interface StoredQuotaResult extends ProviderQuotaResult {
|
|
169
|
-
updatedAt: number;
|
|
170
|
-
}
|
|
171
|
-
export declare function getQuotaAdapter(providerName: string): QuotaAdapter | undefined;
|
|
172
|
-
export declare function getAllQuotaResults(): Record<string, StoredQuotaResult>;
|
|
173
|
-
export declare function getQuotaResult(providerName: string): StoredQuotaResult | undefined;
|
|
174
|
-
export declare function storeQuotaResult(providerName: string, result: ProviderQuotaResult): void;
|
|
175
|
-
export declare function initQuotaStorePersistence(): void;
|
package/dist/plugins.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
// Plugin type declarations
|
|
2
|
-
|
|
3
|
-
export interface PluginMetadata {
|
|
4
|
-
name: string;
|
|
5
|
-
version?: string;
|
|
6
|
-
description?: string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface CCRPluginOptions {
|
|
10
|
-
enabled?: boolean;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export class CCRPlugin {
|
|
14
|
-
name: string;
|
|
15
|
-
metadata: PluginMetadata;
|
|
16
|
-
options: CCRPluginOptions;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const pluginManager: {
|
|
20
|
-
registerPlugin(plugin: CCRPlugin, options?: any): void;
|
|
21
|
-
enablePlugin(name: string, fastify: any): Promise<void>;
|
|
22
|
-
enablePlugins(fastify: any): Promise<void>;
|
|
23
|
-
getPlugins(): PluginMetadata[];
|
|
24
|
-
getPlugin(name: string): CCRPlugin | undefined;
|
|
25
|
-
hasPlugin(name: string): boolean;
|
|
26
|
-
isPluginEnabled(name: string): boolean;
|
|
27
|
-
setPluginEnabled(name: string, enabled: boolean): void;
|
|
28
|
-
removePlugin(name: string): void;
|
|
29
|
-
clear(): void;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export const tokenSpeedPlugin: CCRPlugin;
|
|
33
|
-
|
|
34
|
-
export function getTokenSpeedStats(sessionId: string): {
|
|
35
|
-
ttft: number | null;
|
|
36
|
-
tokensPerSecond: number | null;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export function getGlobalTokenSpeedStats(): {
|
|
40
|
-
avgTtft: number | null;
|
|
41
|
-
avgTokensPerSecond: number | null;
|
|
42
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
// Type declarations for @wengine-ai/llms
|
|
2
|
-
// Manually maintained to avoid path alias issues
|
|
3
|
-
|
|
4
|
-
export interface ProviderHealthState {
|
|
5
|
-
provider: string;
|
|
6
|
-
model: string;
|
|
7
|
-
status: 'closed' | 'open' | 'half-open';
|
|
8
|
-
failureCount: number;
|
|
9
|
-
successCount: number;
|
|
10
|
-
lastFailureTime: number;
|
|
11
|
-
lastProbeTime: number;
|
|
12
|
-
lastError?: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface HealthPoolConfig {
|
|
16
|
-
enabled?: boolean;
|
|
17
|
-
failureThreshold?: number;
|
|
18
|
-
probeIntervalMinutes?: number;
|
|
19
|
-
halfOpenSuccessThreshold?: number;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export class ProviderHealthStore {
|
|
23
|
-
constructor(config?: HealthPoolConfig);
|
|
24
|
-
recordSuccess(provider: string, model: string): void;
|
|
25
|
-
recordFailure(provider: string, model: string, error?: string): void;
|
|
26
|
-
getState(provider: string, model: string): ProviderHealthState | undefined;
|
|
27
|
-
isAvailable(provider: string, model: string): boolean;
|
|
28
|
-
getPriority(provider: string, model: string): number;
|
|
29
|
-
needsProbe(state: ProviderHealthState): boolean;
|
|
30
|
-
markProbeAttempt(provider: string, model: string): void;
|
|
31
|
-
clear(): void;
|
|
32
|
-
getAllStates(): ProviderHealthState[];
|
|
33
|
-
getFailPoolModels(): string[];
|
|
34
|
-
getHalfOpenModels(): string[];
|
|
35
|
-
stopProbeTimer(): void;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function getHealthStore(config?: HealthPoolConfig): ProviderHealthStore;
|
|
39
|
-
export function resetHealthStore(): void;
|