@pikoloo/codex-proxy 1.0.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/LICENSE +21 -0
- package/README.md +199 -0
- package/bin/cli.js +118 -0
- package/docs/ACCOUNTS.md +202 -0
- package/docs/API.md +289 -0
- package/docs/ARCHITECTURE.md +129 -0
- package/docs/CLAUDE_INTEGRATION.md +163 -0
- package/docs/OAUTH.md +85 -0
- package/docs/OPENCLAW.md +34 -0
- package/docs/legal.md +11 -0
- package/images/dashboard-screenshot.png +0 -0
- package/images/demo-screenshot.png +0 -0
- package/images/f757093f-507b-4453-994e-f8275f8b07a9.png +0 -0
- package/package.json +61 -0
- package/public/css/style.css +1502 -0
- package/public/index.html +827 -0
- package/public/js/app.js +601 -0
- package/src/account-manager.js +528 -0
- package/src/account-rotation/index.js +93 -0
- package/src/account-rotation/rate-limits.js +293 -0
- package/src/account-rotation/strategies/base-strategy.js +48 -0
- package/src/account-rotation/strategies/index.js +31 -0
- package/src/account-rotation/strategies/round-robin-strategy.js +42 -0
- package/src/account-rotation/strategies/sticky-strategy.js +97 -0
- package/src/claude-config.js +153 -0
- package/src/cli/accounts.js +557 -0
- package/src/direct-api.js +164 -0
- package/src/format-converter.js +420 -0
- package/src/index.js +46 -0
- package/src/kilo-api.js +68 -0
- package/src/kilo-format-converter.js +285 -0
- package/src/kilo-models.js +103 -0
- package/src/kilo-streamer.js +243 -0
- package/src/middleware/credentials.js +116 -0
- package/src/middleware/sse.js +96 -0
- package/src/model-api.js +189 -0
- package/src/model-mapper.js +157 -0
- package/src/oauth.js +666 -0
- package/src/response-streamer.js +409 -0
- package/src/routes/accounts-route.js +332 -0
- package/src/routes/api-routes.js +98 -0
- package/src/routes/chat-route.js +229 -0
- package/src/routes/claude-config-route.js +121 -0
- package/src/routes/logs-route.js +43 -0
- package/src/routes/messages-route.js +203 -0
- package/src/routes/models-route.js +119 -0
- package/src/routes/settings-route.js +143 -0
- package/src/security.js +142 -0
- package/src/server-settings.js +56 -0
- package/src/server.js +58 -0
- package/src/signature-cache.js +106 -0
- package/src/thinking-utils.js +312 -0
- package/src/utils/logger.js +156 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import EventEmitter from 'events';
|
|
2
|
+
|
|
3
|
+
const COLORS = {
|
|
4
|
+
reset: '\x1b[0m',
|
|
5
|
+
blue: '\x1b[34m',
|
|
6
|
+
green: '\x1b[32m',
|
|
7
|
+
yellow: '\x1b[33m',
|
|
8
|
+
red: '\x1b[31m',
|
|
9
|
+
magenta: '\x1b[35m',
|
|
10
|
+
cyan: '\x1b[36m',
|
|
11
|
+
gray: '\x1b[90m',
|
|
12
|
+
dim: '\x1b[2m'
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const LEVEL_ICONS = {
|
|
16
|
+
INFO: 'ℹ',
|
|
17
|
+
SUCCESS: '✓',
|
|
18
|
+
WARN: '⚠',
|
|
19
|
+
ERROR: '✗',
|
|
20
|
+
DEBUG: '•'
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
class Logger extends EventEmitter {
|
|
24
|
+
constructor() {
|
|
25
|
+
super();
|
|
26
|
+
this.debugEnabled = false;
|
|
27
|
+
this.history = [];
|
|
28
|
+
this.maxHistory = 1000;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
setDebug(enabled) {
|
|
32
|
+
this.debugEnabled = enabled;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
get isDebugEnabled() {
|
|
36
|
+
return this.debugEnabled;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
getHistory() {
|
|
40
|
+
return [...this.history];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
clear() {
|
|
44
|
+
this.history = [];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
_formatTimestamp() {
|
|
48
|
+
return new Date().toISOString().replace('T', ' ').slice(0, 19);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
_formatMessage(args) {
|
|
52
|
+
return args.map(arg => {
|
|
53
|
+
if (arg === null) return 'null';
|
|
54
|
+
if (arg === undefined) return 'undefined';
|
|
55
|
+
if (typeof arg === 'object') {
|
|
56
|
+
try {
|
|
57
|
+
return JSON.stringify(arg, null, 2);
|
|
58
|
+
} catch (e) {
|
|
59
|
+
return String(arg);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return String(arg);
|
|
63
|
+
}).join(' ');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
_log(level, ...args) {
|
|
67
|
+
const timestamp = this._formatTimestamp();
|
|
68
|
+
const icon = LEVEL_ICONS[level] || '•';
|
|
69
|
+
const color = {
|
|
70
|
+
INFO: COLORS.blue,
|
|
71
|
+
SUCCESS: COLORS.green,
|
|
72
|
+
WARN: COLORS.yellow,
|
|
73
|
+
ERROR: COLORS.red,
|
|
74
|
+
DEBUG: COLORS.magenta
|
|
75
|
+
}[level] || COLORS.reset;
|
|
76
|
+
|
|
77
|
+
const message = this._formatMessage(args);
|
|
78
|
+
|
|
79
|
+
if (level === 'DEBUG' && !this.debugEnabled) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const logEntry = {
|
|
84
|
+
timestamp,
|
|
85
|
+
level,
|
|
86
|
+
message,
|
|
87
|
+
icon
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
this.history.push(logEntry);
|
|
91
|
+
if (this.history.length > this.maxHistory) {
|
|
92
|
+
this.history.shift();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
this.emit('log', logEntry);
|
|
96
|
+
|
|
97
|
+
const consoleMessage = `${COLORS.gray}${timestamp}${COLORS.reset} ${color}${icon}${COLORS.reset} ${message}`;
|
|
98
|
+
|
|
99
|
+
switch (level) {
|
|
100
|
+
case 'ERROR':
|
|
101
|
+
console.error(consoleMessage);
|
|
102
|
+
break;
|
|
103
|
+
case 'WARN':
|
|
104
|
+
console.warn(consoleMessage);
|
|
105
|
+
break;
|
|
106
|
+
default:
|
|
107
|
+
console.log(consoleMessage);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
info(...args) {
|
|
112
|
+
this._log('INFO', ...args);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
success(...args) {
|
|
116
|
+
this._log('SUCCESS', ...args);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
warn(...args) {
|
|
120
|
+
this._log('WARN', ...args);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
error(...args) {
|
|
124
|
+
this._log('ERROR', ...args);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
debug(...args) {
|
|
128
|
+
this._log('DEBUG', ...args);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
request(method, path, details = {}) {
|
|
132
|
+
const parts = [`${method}`, path];
|
|
133
|
+
if (details.model) parts.push(`model=${details.model}`);
|
|
134
|
+
if (details.account) parts.push(`account=${details.account}`);
|
|
135
|
+
if (details.stream !== undefined) parts.push(`stream=${details.stream}`);
|
|
136
|
+
if (details.messages) parts.push(`messages=${details.messages}`);
|
|
137
|
+
if (details.tools) parts.push(`tools=${details.tools}`);
|
|
138
|
+
this.info(`[Request] ${parts.join(' | ')}`);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
response(status, details = {}) {
|
|
142
|
+
const parts = [`status=${status}`];
|
|
143
|
+
if (details.model) parts.push(`model=${details.model}`);
|
|
144
|
+
if (details.tokens) parts.push(`tokens=${details.tokens}`);
|
|
145
|
+
if (details.duration) parts.push(`${details.duration}ms`);
|
|
146
|
+
if (details.error) parts.push(`error=${details.error}`);
|
|
147
|
+
|
|
148
|
+
if (status >= 400) {
|
|
149
|
+
this.error(`[Response] ${parts.join(' | ')}`);
|
|
150
|
+
} else {
|
|
151
|
+
this.success(`[Response] ${parts.join(' | ')}`);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export const logger = new Logger();
|