claude-codex-proxy 1.0.5-beta.0 → 1.0.5-beta.10

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.
@@ -10,6 +10,8 @@ export const DEFAULT_MODEL_MAP = {
10
10
  haiku: 'gpt-5.4-mini'
11
11
  };
12
12
 
13
+ export const DEFAULT_CLIENT_KEY_WEEKLY_LIMIT_USD = 50;
14
+
13
15
  export const DEFAULT_SETTINGS = {
14
16
  accountStrategy: 'sticky',
15
17
  defaultCodexModel: 'gpt-5.5',
@@ -24,6 +26,16 @@ function ensureConfigDir() {
24
26
  }
25
27
  }
26
28
 
29
+ function normalizeClientApiKey(clientApiKey) {
30
+ const weeklyLimitUsd = Number(clientApiKey?.weeklyLimitUsd);
31
+ return {
32
+ ...clientApiKey,
33
+ weeklyLimitUsd: Number.isFinite(weeklyLimitUsd) && weeklyLimitUsd >= 0
34
+ ? weeklyLimitUsd
35
+ : DEFAULT_CLIENT_KEY_WEEKLY_LIMIT_USD
36
+ };
37
+ }
38
+
27
39
  function mergeSettings(data = {}) {
28
40
  return {
29
41
  ...DEFAULT_SETTINGS,
@@ -31,7 +43,10 @@ function mergeSettings(data = {}) {
31
43
  modelMap: {
32
44
  ...DEFAULT_MODEL_MAP,
33
45
  ...(data.modelMap || {})
34
- }
46
+ },
47
+ clientApiKeys: Array.isArray(data.clientApiKeys)
48
+ ? data.clientApiKeys.map(normalizeClientApiKey)
49
+ : []
35
50
  };
36
51
  }
37
52
 
@@ -65,5 +80,6 @@ export default {
65
80
  setServerSettings,
66
81
  SETTINGS_FILE,
67
82
  DEFAULT_SETTINGS,
68
- DEFAULT_MODEL_MAP
83
+ DEFAULT_MODEL_MAP,
84
+ DEFAULT_CLIENT_KEY_WEEKLY_LIMIT_USD
69
85
  };
package/src/server.js CHANGED
@@ -7,6 +7,7 @@ import express from 'express';
7
7
  import cors from 'cors';
8
8
 
9
9
  import { ensureAccountsPersist, startAutoRefresh } from './account-manager.js';
10
+ import { getServerHost } from './deployment.js';
10
11
  import { registerApiRoutes } from './routes/api-routes.js';
11
12
 
12
13
  export function createServer({ port, testMode = false, startBackgroundJobs = true, persistAccounts = true }) {
@@ -54,9 +55,9 @@ export function createServer({ port, testMode = false, startBackgroundJobs = tru
54
55
  return app;
55
56
  }
56
57
 
57
- export function startServer({ port }) {
58
+ export function startServer({ port, host = getServerHost() }) {
58
59
  const app = createServer({ port });
59
- return app.listen(port);
60
+ return app.listen(port, host);
60
61
  }
61
62
 
62
63
  export default { createServer, startServer };
@@ -40,6 +40,24 @@ class Logger extends EventEmitter {
40
40
  return [...this.history];
41
41
  }
42
42
 
43
+ /**
44
+ * Returns a newest-first page of in-memory log entries.
45
+ *
46
+ * @param {number} page - One-based page number.
47
+ * @param {number} pageSize - Maximum number of entries per page.
48
+ * @returns {{ logs: object[], total: number }} Requested page and total entry count.
49
+ */
50
+ getHistoryPage(page, pageSize) {
51
+ const total = this.history.length;
52
+ const end = Math.max(0, total - (page - 1) * pageSize);
53
+ const start = Math.max(0, end - pageSize);
54
+
55
+ return {
56
+ logs: this.history.slice(start, end).reverse(),
57
+ total
58
+ };
59
+ }
60
+
43
61
  clear() {
44
62
  this.history = [];
45
63
  }
@@ -0,0 +1,5 @@
1
+ import { getServerSettings } from '../server-settings.js';
2
+
3
+ export function shouldLogRawProxyPayloads() {
4
+ return getServerSettings().logRawProxyPayloads === true;
5
+ }