@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,23 @@
|
|
|
1
|
+
import { OutputHandler, OutputOptions, ConsoleOutputConfig } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Console output handler
|
|
4
|
+
* Supports colored output and multiple log levels
|
|
5
|
+
*/
|
|
6
|
+
export declare class ConsoleOutputHandler implements OutputHandler {
|
|
7
|
+
type: "console";
|
|
8
|
+
private config;
|
|
9
|
+
private colors;
|
|
10
|
+
constructor(config?: ConsoleOutputConfig);
|
|
11
|
+
/**
|
|
12
|
+
* Format output data
|
|
13
|
+
*/
|
|
14
|
+
private formatData;
|
|
15
|
+
/**
|
|
16
|
+
* Convert object to Markdown format
|
|
17
|
+
*/
|
|
18
|
+
private toMarkdown;
|
|
19
|
+
/**
|
|
20
|
+
* Output data
|
|
21
|
+
*/
|
|
22
|
+
output(data: any, options?: OutputOptions): Promise<boolean>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export * from './types';
|
|
2
|
+
export { ConsoleOutputHandler } from './console-handler';
|
|
3
|
+
export { WebhookOutputHandler } from './webhook-handler';
|
|
4
|
+
export { TempFileOutputHandler } from './temp-file-handler';
|
|
5
|
+
export { outputManager, output, outputTo } from './output-manager';
|
|
6
|
+
/**
|
|
7
|
+
* Convenience function: Create and register a Console output handler
|
|
8
|
+
* @param config Console output handler configuration
|
|
9
|
+
* @returns Output manager instance
|
|
10
|
+
*/
|
|
11
|
+
export declare function registerConsoleOutput(config?: import('./types').ConsoleOutputConfig): any;
|
|
12
|
+
/**
|
|
13
|
+
* Convenience function: Create and register a Webhook output handler
|
|
14
|
+
* @param config Webhook output handler configuration
|
|
15
|
+
* @returns Output manager instance
|
|
16
|
+
*/
|
|
17
|
+
export declare function registerWebhookOutput(config: import('./types').WebhookOutputConfig): any;
|
|
18
|
+
/**
|
|
19
|
+
* Convenience function: Create and register a Temp File output handler
|
|
20
|
+
* @param config Temp file output handler configuration
|
|
21
|
+
* @returns Output manager instance
|
|
22
|
+
*/
|
|
23
|
+
export declare function registerTempFileOutput(config?: import('./types').TempFileOutputConfig): any;
|
|
24
|
+
/**
|
|
25
|
+
* Convenience function: Register output handlers in batch
|
|
26
|
+
* @param configs Output handler configuration array
|
|
27
|
+
* @returns Output manager instance
|
|
28
|
+
*/
|
|
29
|
+
export declare function registerOutputHandlers(configs: import('./types').OutputHandlerConfig[]): any;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { OutputHandler, OutputOptions, OutputHandlerConfig } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Output manager
|
|
4
|
+
* Manages multiple output handlers and provides unified output interface
|
|
5
|
+
*/
|
|
6
|
+
declare class OutputManager {
|
|
7
|
+
private handlers;
|
|
8
|
+
private defaultOptions;
|
|
9
|
+
/**
|
|
10
|
+
* Register output handler
|
|
11
|
+
* @param name Output handler name
|
|
12
|
+
* @param handler Output handler instance
|
|
13
|
+
*/
|
|
14
|
+
registerHandler(name: string, handler: OutputHandler): void;
|
|
15
|
+
/**
|
|
16
|
+
* Register output handlers in batch
|
|
17
|
+
* @param configs Output handler configuration array
|
|
18
|
+
*/
|
|
19
|
+
registerHandlers(configs: OutputHandlerConfig[]): void;
|
|
20
|
+
/**
|
|
21
|
+
* Create output handler instance
|
|
22
|
+
* @param config Output handler configuration
|
|
23
|
+
*/
|
|
24
|
+
private createHandler;
|
|
25
|
+
/**
|
|
26
|
+
* Remove output handler
|
|
27
|
+
* @param name Output handler name
|
|
28
|
+
*/
|
|
29
|
+
unregisterHandler(name: string): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Get output handler
|
|
32
|
+
* @param name Output handler name
|
|
33
|
+
*/
|
|
34
|
+
getHandler(name: string): OutputHandler | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Get all output handlers
|
|
37
|
+
*/
|
|
38
|
+
getAllHandlers(): Map<string, OutputHandler>;
|
|
39
|
+
/**
|
|
40
|
+
* Clear all output handlers
|
|
41
|
+
*/
|
|
42
|
+
clearHandlers(): void;
|
|
43
|
+
/**
|
|
44
|
+
* Set default output options
|
|
45
|
+
* @param options Output options
|
|
46
|
+
*/
|
|
47
|
+
setDefaultOptions(options: OutputOptions): void;
|
|
48
|
+
/**
|
|
49
|
+
* Get default output options
|
|
50
|
+
*/
|
|
51
|
+
getDefaultOptions(): OutputOptions;
|
|
52
|
+
/**
|
|
53
|
+
* Output data to all registered output handlers
|
|
54
|
+
* @param data Data to output
|
|
55
|
+
* @param options Output options
|
|
56
|
+
* @returns Promise<{success: string[], failed: string[]}> Names of successful and failed handlers
|
|
57
|
+
*/
|
|
58
|
+
output(data: any, options?: OutputOptions): Promise<{
|
|
59
|
+
success: string[];
|
|
60
|
+
failed: string[];
|
|
61
|
+
}>;
|
|
62
|
+
/**
|
|
63
|
+
* Output data to specified output handlers
|
|
64
|
+
* @param handlerNames Array of output handler names
|
|
65
|
+
* @param data Data to output
|
|
66
|
+
* @param options Output options
|
|
67
|
+
* @returns Promise<{success: string[], failed: string[]}> Names of successful and failed handlers
|
|
68
|
+
*/
|
|
69
|
+
outputTo(handlerNames: string[], data: any, options?: OutputOptions): Promise<{
|
|
70
|
+
success: string[];
|
|
71
|
+
failed: string[];
|
|
72
|
+
}>;
|
|
73
|
+
/**
|
|
74
|
+
* Output data to specified type of output handlers
|
|
75
|
+
* @param type Output handler type
|
|
76
|
+
* @param data Data to output
|
|
77
|
+
* @param options Output options
|
|
78
|
+
* @returns Promise<{success: string[], failed: string[]}> Names of successful and failed handlers
|
|
79
|
+
*/
|
|
80
|
+
outputToType(type: string, data: any, options?: OutputOptions): Promise<{
|
|
81
|
+
success: string[];
|
|
82
|
+
failed: string[];
|
|
83
|
+
}>;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Global output manager instance
|
|
87
|
+
*/
|
|
88
|
+
export declare const outputManager: OutputManager;
|
|
89
|
+
/**
|
|
90
|
+
* Convenience method: Quickly output data to all registered handlers
|
|
91
|
+
* @param data Data to output
|
|
92
|
+
* @param options Output options
|
|
93
|
+
*/
|
|
94
|
+
export declare function output(data: any, options?: OutputOptions): Promise<{
|
|
95
|
+
success: string[];
|
|
96
|
+
failed: string[];
|
|
97
|
+
}>;
|
|
98
|
+
/**
|
|
99
|
+
* Convenience method: Quickly output data to specified type of handlers
|
|
100
|
+
* @param type Output handler type ('console' | 'webhook' | 'websocket')
|
|
101
|
+
* @param data Data to output
|
|
102
|
+
* @param options Output options
|
|
103
|
+
*/
|
|
104
|
+
export declare function outputTo(type: string, data: any, options?: OutputOptions): Promise<{
|
|
105
|
+
success: string[];
|
|
106
|
+
failed: string[];
|
|
107
|
+
}>;
|
|
108
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { OutputHandler, OutputOptions } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Temp file output handler configuration
|
|
4
|
+
*/
|
|
5
|
+
export interface TempFileOutputConfig {
|
|
6
|
+
/**
|
|
7
|
+
* Subdirectory under system temp directory (default: 'claude-code-router')
|
|
8
|
+
*/
|
|
9
|
+
subdirectory?: string;
|
|
10
|
+
/**
|
|
11
|
+
* File extension (default: 'json')
|
|
12
|
+
*/
|
|
13
|
+
extension?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Whether to include timestamp in filename (default: true)
|
|
16
|
+
*/
|
|
17
|
+
includeTimestamp?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Custom prefix for temp files (default: 'session')
|
|
20
|
+
*/
|
|
21
|
+
prefix?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Temp file output handler
|
|
25
|
+
* Writes data to temporary files in system temp directory
|
|
26
|
+
*/
|
|
27
|
+
export declare class TempFileOutputHandler implements OutputHandler {
|
|
28
|
+
type: "temp-file";
|
|
29
|
+
private config;
|
|
30
|
+
private baseDir;
|
|
31
|
+
constructor(config?: TempFileOutputConfig);
|
|
32
|
+
/**
|
|
33
|
+
* Ensure directory exists
|
|
34
|
+
*/
|
|
35
|
+
private ensureDir;
|
|
36
|
+
/**
|
|
37
|
+
* Get file path for temp file
|
|
38
|
+
*/
|
|
39
|
+
private getFilePath;
|
|
40
|
+
/**
|
|
41
|
+
* Output data to temp file
|
|
42
|
+
*/
|
|
43
|
+
output(data: any, options?: OutputOptions): Promise<boolean>;
|
|
44
|
+
/**
|
|
45
|
+
* Get the base directory where temp files are stored
|
|
46
|
+
*/
|
|
47
|
+
getBaseDir(): string;
|
|
48
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Output handler interface
|
|
3
|
+
* All output handlers must implement this interface
|
|
4
|
+
*/
|
|
5
|
+
export interface OutputHandler {
|
|
6
|
+
/**
|
|
7
|
+
* Output handler type name
|
|
8
|
+
*/
|
|
9
|
+
type: string;
|
|
10
|
+
/**
|
|
11
|
+
* Output data
|
|
12
|
+
* @param data Data to output
|
|
13
|
+
* @param options Output options
|
|
14
|
+
* @returns Promise<boolean> Whether output was successful
|
|
15
|
+
*/
|
|
16
|
+
output(data: any, options?: OutputOptions): Promise<boolean>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Output options
|
|
20
|
+
*/
|
|
21
|
+
export interface OutputOptions {
|
|
22
|
+
/**
|
|
23
|
+
* Output format
|
|
24
|
+
*/
|
|
25
|
+
format?: 'json' | 'text' | 'markdown';
|
|
26
|
+
/**
|
|
27
|
+
* Whether to include timestamp
|
|
28
|
+
*/
|
|
29
|
+
timestamp?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Custom prefix
|
|
32
|
+
*/
|
|
33
|
+
prefix?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Additional metadata
|
|
36
|
+
*/
|
|
37
|
+
metadata?: Record<string, any>;
|
|
38
|
+
/**
|
|
39
|
+
* Timeout (milliseconds)
|
|
40
|
+
*/
|
|
41
|
+
timeout?: number;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Console output handler configuration
|
|
45
|
+
*/
|
|
46
|
+
export interface ConsoleOutputConfig {
|
|
47
|
+
/**
|
|
48
|
+
* Whether to use colored output
|
|
49
|
+
*/
|
|
50
|
+
colors?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Log level
|
|
53
|
+
*/
|
|
54
|
+
level?: 'log' | 'info' | 'warn' | 'error' | 'debug';
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Webhook output handler configuration
|
|
58
|
+
*/
|
|
59
|
+
export interface WebhookOutputConfig {
|
|
60
|
+
/**
|
|
61
|
+
* Webhook URL
|
|
62
|
+
*/
|
|
63
|
+
url: string;
|
|
64
|
+
/**
|
|
65
|
+
* HTTP request method
|
|
66
|
+
*/
|
|
67
|
+
method?: 'POST' | 'PUT' | 'PATCH';
|
|
68
|
+
/**
|
|
69
|
+
* Request headers
|
|
70
|
+
*/
|
|
71
|
+
headers?: Record<string, string>;
|
|
72
|
+
/**
|
|
73
|
+
* Authentication information
|
|
74
|
+
*/
|
|
75
|
+
auth?: {
|
|
76
|
+
type: 'bearer' | 'basic' | 'custom';
|
|
77
|
+
token?: string;
|
|
78
|
+
username?: string;
|
|
79
|
+
password?: string;
|
|
80
|
+
custom?: {
|
|
81
|
+
header: string;
|
|
82
|
+
value: string;
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Retry configuration
|
|
87
|
+
*/
|
|
88
|
+
retry?: {
|
|
89
|
+
maxAttempts: number;
|
|
90
|
+
backoffMs: number;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Whether to handle failures silently (only log, don't throw)
|
|
94
|
+
*/
|
|
95
|
+
silent?: boolean;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* WebSocket output handler configuration (reserved for future use)
|
|
99
|
+
*/
|
|
100
|
+
export interface WebSocketOutputConfig {
|
|
101
|
+
/**
|
|
102
|
+
* WebSocket URL
|
|
103
|
+
*/
|
|
104
|
+
url: string;
|
|
105
|
+
/**
|
|
106
|
+
* Reconnection configuration
|
|
107
|
+
*/
|
|
108
|
+
reconnect?: {
|
|
109
|
+
maxAttempts: number;
|
|
110
|
+
intervalMs: number;
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Heartbeat configuration
|
|
114
|
+
*/
|
|
115
|
+
heartbeat?: {
|
|
116
|
+
intervalMs: number;
|
|
117
|
+
message?: string;
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Temp file output handler configuration
|
|
122
|
+
*/
|
|
123
|
+
export interface TempFileOutputConfig {
|
|
124
|
+
/**
|
|
125
|
+
* Subdirectory under system temp directory (default: 'claude-code-router')
|
|
126
|
+
*/
|
|
127
|
+
subdirectory?: string;
|
|
128
|
+
/**
|
|
129
|
+
* File extension (default: 'json')
|
|
130
|
+
*/
|
|
131
|
+
extension?: string;
|
|
132
|
+
/**
|
|
133
|
+
* Whether to include timestamp in filename (default: true)
|
|
134
|
+
*/
|
|
135
|
+
includeTimestamp?: boolean;
|
|
136
|
+
/**
|
|
137
|
+
* Custom prefix for temp files (default: 'session')
|
|
138
|
+
*/
|
|
139
|
+
prefix?: string;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Output handler registration configuration
|
|
143
|
+
*/
|
|
144
|
+
export interface OutputHandlerConfig {
|
|
145
|
+
/**
|
|
146
|
+
* Output handler type
|
|
147
|
+
*/
|
|
148
|
+
type: 'console' | 'webhook' | 'websocket' | 'temp-file';
|
|
149
|
+
/**
|
|
150
|
+
* Whether enabled
|
|
151
|
+
*/
|
|
152
|
+
enabled?: boolean;
|
|
153
|
+
/**
|
|
154
|
+
* Configuration options
|
|
155
|
+
*/
|
|
156
|
+
config?: ConsoleOutputConfig | WebhookOutputConfig | WebSocketOutputConfig | TempFileOutputConfig;
|
|
157
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { OutputHandler, OutputOptions, WebhookOutputConfig } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Webhook output handler
|
|
4
|
+
* Supports sending data to HTTP endpoints with retry and authentication
|
|
5
|
+
*/
|
|
6
|
+
export declare class WebhookOutputHandler implements OutputHandler {
|
|
7
|
+
type: "webhook";
|
|
8
|
+
private config;
|
|
9
|
+
private defaultTimeout;
|
|
10
|
+
constructor(config: WebhookOutputConfig);
|
|
11
|
+
/**
|
|
12
|
+
* Build request headers
|
|
13
|
+
*/
|
|
14
|
+
private buildHeaders;
|
|
15
|
+
/**
|
|
16
|
+
* Build request body
|
|
17
|
+
*/
|
|
18
|
+
private buildBody;
|
|
19
|
+
/**
|
|
20
|
+
* Send HTTP request
|
|
21
|
+
*/
|
|
22
|
+
private sendRequest;
|
|
23
|
+
/**
|
|
24
|
+
* Delay function (for retry backoff)
|
|
25
|
+
*/
|
|
26
|
+
private delay;
|
|
27
|
+
/**
|
|
28
|
+
* Send request with retry
|
|
29
|
+
*/
|
|
30
|
+
private sendWithRetry;
|
|
31
|
+
/**
|
|
32
|
+
* Output data to Webhook
|
|
33
|
+
*/
|
|
34
|
+
output(data: any, options?: OutputOptions): Promise<boolean>;
|
|
35
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { FastifyInstance } from 'fastify';
|
|
2
|
+
import { CCRPlugin, PluginMetadata } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Plugin manager
|
|
5
|
+
*/
|
|
6
|
+
declare class PluginManager {
|
|
7
|
+
private plugins;
|
|
8
|
+
private pluginInstances;
|
|
9
|
+
/**
|
|
10
|
+
* Register a plugin
|
|
11
|
+
* @param plugin Plugin instance
|
|
12
|
+
* @param options Plugin configuration options
|
|
13
|
+
*/
|
|
14
|
+
registerPlugin(plugin: CCRPlugin, options?: any): void;
|
|
15
|
+
/**
|
|
16
|
+
* Enable a single plugin
|
|
17
|
+
* @param name Plugin name
|
|
18
|
+
* @param fastify Fastify instance
|
|
19
|
+
*/
|
|
20
|
+
enablePlugin(name: string, fastify: FastifyInstance): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Enable all registered plugins in batch
|
|
23
|
+
* @param fastify Fastify instance
|
|
24
|
+
*/
|
|
25
|
+
enablePlugins(fastify: FastifyInstance): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Get list of registered plugins
|
|
28
|
+
*/
|
|
29
|
+
getPlugins(): PluginMetadata[];
|
|
30
|
+
/**
|
|
31
|
+
* Get plugin instance
|
|
32
|
+
* @param name Plugin name
|
|
33
|
+
*/
|
|
34
|
+
getPlugin(name: string): CCRPlugin | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Check if plugin is registered
|
|
37
|
+
* @param name Plugin name
|
|
38
|
+
*/
|
|
39
|
+
hasPlugin(name: string): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Check if plugin is enabled
|
|
42
|
+
* @param name Plugin name
|
|
43
|
+
*/
|
|
44
|
+
isPluginEnabled(name: string): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Dynamically enable/disable plugin
|
|
47
|
+
* @param name Plugin name
|
|
48
|
+
* @param enabled Whether to enable
|
|
49
|
+
*/
|
|
50
|
+
setPluginEnabled(name: string, enabled: boolean): void;
|
|
51
|
+
/**
|
|
52
|
+
* Remove plugin
|
|
53
|
+
* @param name Plugin name
|
|
54
|
+
*/
|
|
55
|
+
removePlugin(name: string): void;
|
|
56
|
+
/**
|
|
57
|
+
* Clear all plugins
|
|
58
|
+
*/
|
|
59
|
+
clear(): void;
|
|
60
|
+
}
|
|
61
|
+
export declare const pluginManager: PluginManager;
|
|
62
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { FastifyPluginAsync } from 'fastify';
|
|
2
|
+
/**
|
|
3
|
+
* Plugin configuration interface
|
|
4
|
+
*/
|
|
5
|
+
export interface CCRPluginOptions {
|
|
6
|
+
enabled?: boolean;
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Plugin interface
|
|
11
|
+
*/
|
|
12
|
+
export interface CCRPlugin {
|
|
13
|
+
name: string;
|
|
14
|
+
version?: string;
|
|
15
|
+
description?: string;
|
|
16
|
+
register: FastifyPluginAsync<CCRPluginOptions>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Plugin metadata
|
|
20
|
+
*/
|
|
21
|
+
export interface PluginMetadata {
|
|
22
|
+
name: string;
|
|
23
|
+
enabled: boolean;
|
|
24
|
+
options?: any;
|
|
25
|
+
}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { FastifyInstance, FastifyPluginAsync, FastifyPluginCallback, FastifyPluginOptions, FastifyRegisterOptions, preHandlerHookHandler, onRequestHookHandler, preParsingHookHandler, preValidationHookHandler, preSerializationHookHandler, onSendHookHandler, onResponseHookHandler, onTimeoutHookHandler, onErrorHookHandler, onRouteHookHandler, onRegisterHookHandler, onReadyHookHandler, onListenHookHandler, onCloseHookHandler, FastifyServerOptions } from "fastify";
|
|
2
|
+
import { ConfigService, AppConfig } from "./services/config";
|
|
3
|
+
import { ProviderService } from "./services/provider";
|
|
4
|
+
import { TransformerService } from "./services/transformer";
|
|
5
|
+
import { TokenizerService } from "./services/tokenizer";
|
|
6
|
+
import { router, calculateTokenCount, searchProjectBySession } from "./utils/router";
|
|
7
|
+
import { sessionUsageCache } from "./utils/cache";
|
|
8
|
+
import { ActiveProbeService } from "./services/active-probe";
|
|
9
|
+
import type { CcrPreHandlerCallbacks } from "./ccr/request-pipeline";
|
|
10
|
+
declare module "fastify" {
|
|
11
|
+
interface FastifyRequest {
|
|
12
|
+
provider?: string;
|
|
13
|
+
model?: string;
|
|
14
|
+
scenarioType?: string;
|
|
15
|
+
}
|
|
16
|
+
interface FastifyInstance {
|
|
17
|
+
_server?: Server;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export interface ServerOptions extends FastifyServerOptions {
|
|
21
|
+
initialConfig?: AppConfig;
|
|
22
|
+
jsonPath?: string;
|
|
23
|
+
envPath?: string;
|
|
24
|
+
useEnvFile?: boolean;
|
|
25
|
+
useJsonFile?: boolean;
|
|
26
|
+
useEnvironmentVariables?: boolean;
|
|
27
|
+
}
|
|
28
|
+
declare class Server {
|
|
29
|
+
app: FastifyInstance;
|
|
30
|
+
configService: ConfigService;
|
|
31
|
+
providerService: ProviderService;
|
|
32
|
+
transformerService: TransformerService;
|
|
33
|
+
tokenizerService: TokenizerService;
|
|
34
|
+
activeProbeService?: ActiveProbeService;
|
|
35
|
+
recordUsage?: (data: any) => void;
|
|
36
|
+
private readonly readiness;
|
|
37
|
+
private mainNamespaceRegistered;
|
|
38
|
+
private signalHandlersRegistered;
|
|
39
|
+
ccrPreHandlerCallbacks?: CcrPreHandlerCallbacks;
|
|
40
|
+
constructor(options?: ServerOptions);
|
|
41
|
+
ready(): Promise<void>;
|
|
42
|
+
register<Options extends FastifyPluginOptions = FastifyPluginOptions>(plugin: FastifyPluginAsync<Options> | FastifyPluginCallback<Options>, options?: FastifyRegisterOptions<Options>): Promise<void>;
|
|
43
|
+
addHook(hookName: "onRequest", hookFunction: onRequestHookHandler): void;
|
|
44
|
+
addHook(hookName: "preParsing", hookFunction: preParsingHookHandler): void;
|
|
45
|
+
addHook(hookName: "preValidation", hookFunction: preValidationHookHandler): void;
|
|
46
|
+
addHook(hookName: "preHandler", hookFunction: preHandlerHookHandler): void;
|
|
47
|
+
addHook(hookName: "preSerialization", hookFunction: preSerializationHookHandler): void;
|
|
48
|
+
addHook(hookName: "onSend", hookFunction: onSendHookHandler): void;
|
|
49
|
+
addHook(hookName: "onResponse", hookFunction: onResponseHookHandler): void;
|
|
50
|
+
addHook(hookName: "onTimeout", hookFunction: onTimeoutHookHandler): void;
|
|
51
|
+
addHook(hookName: "onError", hookFunction: onErrorHookHandler): void;
|
|
52
|
+
addHook(hookName: "onRoute", hookFunction: onRouteHookHandler): void;
|
|
53
|
+
addHook(hookName: "onRegister", hookFunction: onRegisterHookHandler): void;
|
|
54
|
+
addHook(hookName: "onReady", hookFunction: onReadyHookHandler): void;
|
|
55
|
+
addHook(hookName: "onListen", hookFunction: onListenHookHandler): void;
|
|
56
|
+
addHook(hookName: "onClose", hookFunction: onCloseHookHandler): void;
|
|
57
|
+
/**
|
|
58
|
+
* Register one API namespace with an explicit request-phase pipeline.
|
|
59
|
+
*
|
|
60
|
+
* Namespace hook order is independent of external/global hook registration:
|
|
61
|
+
* request normalize → adapter → router → provider model normalization → handler.
|
|
62
|
+
*/
|
|
63
|
+
registerNamespace(name: string, options?: any): Promise<void>;
|
|
64
|
+
start(): Promise<void>;
|
|
65
|
+
}
|
|
66
|
+
export default Server;
|
|
67
|
+
export { sessionUsageCache };
|
|
68
|
+
export { router };
|
|
69
|
+
export { calculateTokenCount };
|
|
70
|
+
export { searchProjectBySession };
|
|
71
|
+
export { extractSessionIdFromUserId, normalizeSessionId } from "./utils/session-id";
|
|
72
|
+
export { applyClientAdapter, builtinClientAdapterRegistry, clearClientAdapterCaches, detectClientType, getClientAdapter, isClientType, } from "./clients/adapters";
|
|
73
|
+
export type { ClientAdapter, ClientContext, ClientType, ClientUsageScope, } from "./clients/adapters";
|
|
74
|
+
export type { RouterScenarioType, RouterFallbackConfig } from "./utils/router";
|
|
75
|
+
export { ProjectRoutingError, diagnoseResolutionFailure } from "./utils/router";
|
|
76
|
+
export { ConfigService } from "./services/config";
|
|
77
|
+
export { ProviderService } from "./services/provider";
|
|
78
|
+
export { TransformerService } from "./services/transformer";
|
|
79
|
+
export { TokenizerService } from "./services/tokenizer";
|
|
80
|
+
export { pluginManager, tokenSpeedPlugin } from "./plugins";
|
|
81
|
+
export type { CCRPlugin, CCRPluginOptions, PluginMetadata } from "./plugins";
|
|
82
|
+
export { SSEParserTransform, SSESerializerTransform, rewriteStream } from "./utils/sse";
|
|
83
|
+
export { getHealthStore, ProviderHealthStore } from "./services/provider-health";
|
|
84
|
+
export type { ProviderHealthState, HealthPoolConfig } from "./services/provider-health";
|
|
85
|
+
export { getAllRateLimitInfo, getRateLimitInfo, initRateLimitPersistence } from "./services/rate-limit";
|
|
86
|
+
export type { RateLimitInfo } from "./services/rate-limit";
|
|
87
|
+
export { getQuotaAdapter } from "./services/quota-adapters";
|
|
88
|
+
export type { QuotaAdapter, ProviderQuotaResult } from "./services/quota-adapters";
|
|
89
|
+
export { getAllQuotaResults, getQuotaResult, storeQuotaResult, initQuotaStorePersistence } from "./services/quota-store";
|
|
90
|
+
export { initProviderHealthPersistence } from "./services/provider-health";
|
|
91
|
+
export type { StoredQuotaResult } from "./services/quota-store";
|
|
92
|
+
export { getActiveProbeService, startActiveProbe, stopActiveProbe, resetActiveProbeService, ActiveProbeService } from "./services/active-probe";
|
|
93
|
+
export type { ActiveProbeConfig } from "./services/active-probe";
|
|
94
|
+
export { setRuntimeDebugLog, getRuntimeDebugLog } from "./utils/debug-log";
|
|
95
|
+
export { closeProxyDispatchers, getConfiguredProxyUrl, getProxyDispatcher, isGlobalProxyEnabled, resolveProviderProxyUrl } from "./services/proxy";
|
|
96
|
+
/**
|
|
97
|
+
* Create the full CCR runtime. Loaded lazily to avoid a module cycle between
|
|
98
|
+
* the base Server class and the CCR composition root.
|
|
99
|
+
*/
|
|
100
|
+
export declare function createCcrServer(options?: import("./ccr/create-server").CcrRunOptions): Promise<Server>;
|
|
101
|
+
/** Backward-compatible name used by the CLI and the legacy server facade. */
|
|
102
|
+
export declare const getServer: typeof createCcrServer;
|
|
103
|
+
export type { CcrRunOptions as RunOptions } from "./ccr/create-server";
|
|
104
|
+
export type { IAgent, ITool } from "./ccr/agents/type";
|
|
105
|
+
export { initDir, initConfig, readConfigFile, readConfigFileRaw, writeConfigFile, backupConfigFile } from "./ccr/config";
|
|
106
|
+
export { normalizeUsagePayload, mergeUsageCapture } from "./ccr/usage-merge";
|
|
107
|
+
export { collectReachableModelKeys, reconcileHealthStore, clearProviderHealth } from "./ccr/health-reconcile";
|
|
108
|
+
export { listAnthropicCompatibleModels } from "./ccr/models";
|
|
109
|
+
export { apiKeyAuth } from "./ccr/auth";
|
|
110
|
+
export * as usageStore from "./ccr/usage-store";
|