commons-proxy 2.0.0

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.
Files changed (99) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +757 -0
  3. package/bin/cli.js +146 -0
  4. package/package.json +97 -0
  5. package/public/Complaint Details.pdf +0 -0
  6. package/public/Cyber Crime Portal.pdf +0 -0
  7. package/public/app.js +229 -0
  8. package/public/css/src/input.css +523 -0
  9. package/public/css/style.css +1 -0
  10. package/public/favicon.png +0 -0
  11. package/public/index.html +549 -0
  12. package/public/js/components/account-manager.js +356 -0
  13. package/public/js/components/add-account-modal.js +414 -0
  14. package/public/js/components/claude-config.js +420 -0
  15. package/public/js/components/dashboard/charts.js +605 -0
  16. package/public/js/components/dashboard/filters.js +362 -0
  17. package/public/js/components/dashboard/stats.js +110 -0
  18. package/public/js/components/dashboard.js +236 -0
  19. package/public/js/components/logs-viewer.js +100 -0
  20. package/public/js/components/models.js +36 -0
  21. package/public/js/components/server-config.js +349 -0
  22. package/public/js/config/constants.js +102 -0
  23. package/public/js/data-store.js +375 -0
  24. package/public/js/settings-store.js +58 -0
  25. package/public/js/store.js +99 -0
  26. package/public/js/translations/en.js +367 -0
  27. package/public/js/translations/id.js +412 -0
  28. package/public/js/translations/pt.js +308 -0
  29. package/public/js/translations/tr.js +358 -0
  30. package/public/js/translations/zh.js +373 -0
  31. package/public/js/utils/account-actions.js +189 -0
  32. package/public/js/utils/error-handler.js +96 -0
  33. package/public/js/utils/model-config.js +42 -0
  34. package/public/js/utils/ui-logger.js +143 -0
  35. package/public/js/utils/validators.js +77 -0
  36. package/public/js/utils.js +69 -0
  37. package/public/proxy-server-64.png +0 -0
  38. package/public/views/accounts.html +361 -0
  39. package/public/views/dashboard.html +484 -0
  40. package/public/views/logs.html +97 -0
  41. package/public/views/models.html +331 -0
  42. package/public/views/settings.html +1327 -0
  43. package/src/account-manager/credentials.js +378 -0
  44. package/src/account-manager/index.js +462 -0
  45. package/src/account-manager/onboarding.js +112 -0
  46. package/src/account-manager/rate-limits.js +369 -0
  47. package/src/account-manager/storage.js +160 -0
  48. package/src/account-manager/strategies/base-strategy.js +109 -0
  49. package/src/account-manager/strategies/hybrid-strategy.js +339 -0
  50. package/src/account-manager/strategies/index.js +79 -0
  51. package/src/account-manager/strategies/round-robin-strategy.js +76 -0
  52. package/src/account-manager/strategies/sticky-strategy.js +138 -0
  53. package/src/account-manager/strategies/trackers/health-tracker.js +162 -0
  54. package/src/account-manager/strategies/trackers/index.js +9 -0
  55. package/src/account-manager/strategies/trackers/quota-tracker.js +120 -0
  56. package/src/account-manager/strategies/trackers/token-bucket-tracker.js +155 -0
  57. package/src/auth/database.js +169 -0
  58. package/src/auth/oauth.js +548 -0
  59. package/src/auth/token-extractor.js +117 -0
  60. package/src/cli/accounts.js +648 -0
  61. package/src/cloudcode/index.js +29 -0
  62. package/src/cloudcode/message-handler.js +510 -0
  63. package/src/cloudcode/model-api.js +248 -0
  64. package/src/cloudcode/rate-limit-parser.js +235 -0
  65. package/src/cloudcode/request-builder.js +93 -0
  66. package/src/cloudcode/session-manager.js +47 -0
  67. package/src/cloudcode/sse-parser.js +121 -0
  68. package/src/cloudcode/sse-streamer.js +293 -0
  69. package/src/cloudcode/streaming-handler.js +615 -0
  70. package/src/config.js +125 -0
  71. package/src/constants.js +407 -0
  72. package/src/errors.js +242 -0
  73. package/src/fallback-config.js +29 -0
  74. package/src/format/content-converter.js +193 -0
  75. package/src/format/index.js +20 -0
  76. package/src/format/request-converter.js +255 -0
  77. package/src/format/response-converter.js +120 -0
  78. package/src/format/schema-sanitizer.js +673 -0
  79. package/src/format/signature-cache.js +88 -0
  80. package/src/format/thinking-utils.js +648 -0
  81. package/src/index.js +148 -0
  82. package/src/modules/usage-stats.js +205 -0
  83. package/src/providers/anthropic-provider.js +258 -0
  84. package/src/providers/base-provider.js +157 -0
  85. package/src/providers/cloudcode.js +94 -0
  86. package/src/providers/copilot.js +399 -0
  87. package/src/providers/github-provider.js +287 -0
  88. package/src/providers/google-provider.js +192 -0
  89. package/src/providers/index.js +211 -0
  90. package/src/providers/openai-compatible.js +265 -0
  91. package/src/providers/openai-provider.js +271 -0
  92. package/src/providers/openrouter-provider.js +325 -0
  93. package/src/providers/setup.js +83 -0
  94. package/src/server.js +870 -0
  95. package/src/utils/claude-config.js +245 -0
  96. package/src/utils/helpers.js +51 -0
  97. package/src/utils/logger.js +142 -0
  98. package/src/utils/native-module-helper.js +162 -0
  99. package/src/webui/index.js +1134 -0
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Signature Cache
3
+ * In-memory cache for Gemini thoughtSignatures
4
+ *
5
+ * Gemini models require thoughtSignature on tool calls, but Claude Code
6
+ * strips non-standard fields. This cache stores signatures by tool_use_id
7
+ * so they can be restored in subsequent requests.
8
+ *
9
+ * Also caches thinking block signatures with model family for cross-model
10
+ * compatibility checking.
11
+ */
12
+
13
+ import { GEMINI_SIGNATURE_CACHE_TTL_MS, MIN_SIGNATURE_LENGTH } from '../constants.js';
14
+
15
+ const signatureCache = new Map();
16
+ const thinkingSignatureCache = new Map();
17
+
18
+ /**
19
+ * Store a signature for a tool_use_id
20
+ * @param {string} toolUseId - The tool use ID
21
+ * @param {string} signature - The thoughtSignature to cache
22
+ */
23
+ export function cacheSignature(toolUseId, signature) {
24
+ if (!toolUseId || !signature) return;
25
+ signatureCache.set(toolUseId, {
26
+ signature,
27
+ timestamp: Date.now()
28
+ });
29
+ }
30
+
31
+ /**
32
+ * Get a cached signature for a tool_use_id
33
+ * @param {string} toolUseId - The tool use ID
34
+ * @returns {string|null} The cached signature or null if not found/expired
35
+ */
36
+ export function getCachedSignature(toolUseId) {
37
+ if (!toolUseId) return null;
38
+ const entry = signatureCache.get(toolUseId);
39
+ if (!entry) return null;
40
+
41
+ // Check TTL
42
+ if (Date.now() - entry.timestamp > GEMINI_SIGNATURE_CACHE_TTL_MS) {
43
+ signatureCache.delete(toolUseId);
44
+ return null;
45
+ }
46
+
47
+ return entry.signature;
48
+ }
49
+
50
+ /**
51
+ * Cache a thinking block signature with its model family
52
+ * @param {string} signature - The thinking signature to cache
53
+ * @param {string} modelFamily - The model family ('claude' or 'gemini')
54
+ */
55
+ export function cacheThinkingSignature(signature, modelFamily) {
56
+ if (!signature || signature.length < MIN_SIGNATURE_LENGTH) return;
57
+ thinkingSignatureCache.set(signature, {
58
+ modelFamily,
59
+ timestamp: Date.now()
60
+ });
61
+ }
62
+
63
+ /**
64
+ * Get the cached model family for a thinking signature
65
+ * @param {string} signature - The signature to look up
66
+ * @returns {string|null} 'claude', 'gemini', or null if not found/expired
67
+ */
68
+ export function getCachedSignatureFamily(signature) {
69
+ if (!signature) return null;
70
+ const entry = thinkingSignatureCache.get(signature);
71
+ if (!entry) return null;
72
+
73
+ // Check TTL
74
+ if (Date.now() - entry.timestamp > GEMINI_SIGNATURE_CACHE_TTL_MS) {
75
+ thinkingSignatureCache.delete(signature);
76
+ return null;
77
+ }
78
+
79
+ return entry.modelFamily;
80
+ }
81
+
82
+ /**
83
+ * Clear all entries from the thinking signature cache.
84
+ * Used for testing cold cache scenarios.
85
+ */
86
+ export function clearThinkingSignatureCache() {
87
+ thinkingSignatureCache.clear();
88
+ }