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,42 @@
1
+ /**
2
+ * Model Configuration Utilities
3
+ * Shared functions for model configuration updates
4
+ */
5
+ window.ModelConfigUtils = window.ModelConfigUtils || {};
6
+
7
+ /**
8
+ * Update model configuration with authentication and optimistic updates
9
+ * @param {string} modelId - The model ID to update
10
+ * @param {object} configUpdates - Configuration updates (pinned, hidden, alias, mapping)
11
+ * @returns {Promise<void>}
12
+ */
13
+ window.ModelConfigUtils.updateModelConfig = async function(modelId, configUpdates) {
14
+ return window.ErrorHandler.safeAsync(async () => {
15
+ const store = Alpine.store('global');
16
+
17
+ const { response, newPassword } = await window.utils.request('/api/models/config', {
18
+ method: 'POST',
19
+ headers: { 'Content-Type': 'application/json' },
20
+ body: JSON.stringify({ modelId, config: configUpdates })
21
+ }, store.webuiPassword);
22
+
23
+ // Update password if server provided a new one
24
+ if (newPassword) {
25
+ store.webuiPassword = newPassword;
26
+ }
27
+
28
+ if (!response.ok) {
29
+ throw new Error(store.t('failedToUpdateModelConfig'));
30
+ }
31
+
32
+ // Optimistic update of local state
33
+ const dataStore = Alpine.store('data');
34
+ dataStore.modelConfig[modelId] = {
35
+ ...dataStore.modelConfig[modelId],
36
+ ...configUpdates
37
+ };
38
+
39
+ // Recompute quota rows to reflect changes
40
+ dataStore.computeQuotaRows();
41
+ }, Alpine.store('global').t('failedToUpdateModelConfig'));
42
+ };
@@ -0,0 +1,143 @@
1
+ /**
2
+ * UI Logger Utility
3
+ * Provides conditional logging for the web UI to reduce console spam in production.
4
+ * Wraps console methods and only outputs when debug mode is enabled.
5
+ *
6
+ * Usage:
7
+ * window.UILogger.debug('message') - Only logs if debug mode enabled
8
+ * window.UILogger.info('message') - Only logs if debug mode enabled
9
+ * window.UILogger.warn('message') - Always logs (important warnings)
10
+ * window.UILogger.error('message') - Always logs (errors should always be visible)
11
+ *
12
+ * Enable debug mode:
13
+ * - Set localStorage.setItem('ag_debug', 'true') in browser console
14
+ * - Or pass ?debug=true in URL
15
+ */
16
+
17
+ (function() {
18
+ 'use strict';
19
+
20
+ // Check if debug mode is enabled
21
+ function isDebugEnabled() {
22
+ // Check URL parameter
23
+ const urlParams = new URLSearchParams(window.location.search);
24
+ if (urlParams.get('debug') === 'true') {
25
+ return true;
26
+ }
27
+
28
+ // Check localStorage
29
+ try {
30
+ return localStorage.getItem('ag_debug') === 'true';
31
+ } catch (e) {
32
+ return false;
33
+ }
34
+ }
35
+
36
+ // Cache debug state (can be refreshed)
37
+ let debugEnabled = isDebugEnabled();
38
+
39
+ window.UILogger = {
40
+ /**
41
+ * Refresh debug state (call after changing localStorage)
42
+ */
43
+ refresh() {
44
+ debugEnabled = isDebugEnabled();
45
+ },
46
+
47
+ /**
48
+ * Enable debug mode
49
+ */
50
+ enableDebug() {
51
+ try {
52
+ localStorage.setItem('ag_debug', 'true');
53
+ debugEnabled = true;
54
+ console.info('[UILogger] Debug mode enabled. Refresh page to see all logs.');
55
+ } catch (e) {
56
+ console.warn('[UILogger] Could not save debug preference');
57
+ }
58
+ },
59
+
60
+ /**
61
+ * Disable debug mode
62
+ */
63
+ disableDebug() {
64
+ try {
65
+ localStorage.removeItem('ag_debug');
66
+ debugEnabled = false;
67
+ console.info('[UILogger] Debug mode disabled.');
68
+ } catch (e) {
69
+ // Ignore
70
+ }
71
+ },
72
+
73
+ /**
74
+ * Check if debug mode is enabled
75
+ * @returns {boolean}
76
+ */
77
+ isDebug() {
78
+ return debugEnabled;
79
+ },
80
+
81
+ /**
82
+ * Debug level - only logs if debug mode enabled
83
+ * Use for verbose debugging info (chart updates, cache operations, etc.)
84
+ */
85
+ debug(...args) {
86
+ if (debugEnabled) {
87
+ console.log('[DEBUG]', ...args);
88
+ }
89
+ },
90
+
91
+ /**
92
+ * Info level - only logs if debug mode enabled
93
+ * Use for informational messages that aren't errors
94
+ */
95
+ info(...args) {
96
+ if (debugEnabled) {
97
+ console.info('[INFO]', ...args);
98
+ }
99
+ },
100
+
101
+ /**
102
+ * Log level - alias for debug
103
+ */
104
+ log(...args) {
105
+ if (debugEnabled) {
106
+ console.log(...args);
107
+ }
108
+ },
109
+
110
+ /**
111
+ * Warn level - always logs
112
+ * Use for important warnings that users should see
113
+ * But suppress noisy/expected warnings unless in debug mode
114
+ */
115
+ warn(...args) {
116
+ // In production, only show critical warnings
117
+ // In debug mode, show all warnings
118
+ if (debugEnabled) {
119
+ console.warn(...args);
120
+ }
121
+ },
122
+
123
+ /**
124
+ * Warn level that always shows (for critical warnings)
125
+ */
126
+ warnAlways(...args) {
127
+ console.warn(...args);
128
+ },
129
+
130
+ /**
131
+ * Error level - always logs
132
+ * Errors should always be visible for debugging
133
+ */
134
+ error(...args) {
135
+ console.error(...args);
136
+ }
137
+ };
138
+
139
+ // Log initial state (only in debug mode)
140
+ if (debugEnabled) {
141
+ console.info('[UILogger] Debug mode is ON. Set localStorage ag_debug=false to disable.');
142
+ }
143
+ })();
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Input Validation Utilities
3
+ * Provides validation functions for user inputs
4
+ */
5
+ window.Validators = window.Validators || {};
6
+
7
+ /**
8
+ * Validate a number is within a range
9
+ * @param {number} value - Value to validate
10
+ * @param {number} min - Minimum allowed value (inclusive)
11
+ * @param {number} max - Maximum allowed value (inclusive)
12
+ * @param {string} fieldName - Name of the field for error messages
13
+ * @returns {object} { isValid: boolean, value: number, error: string|null }
14
+ */
15
+ window.Validators.validateRange = function(value, min, max, fieldName = 'Value') {
16
+ const numValue = Number(value);
17
+ const t = Alpine.store('global').t;
18
+
19
+ if (isNaN(numValue)) {
20
+ return {
21
+ isValid: false,
22
+ value: min,
23
+ error: t('mustBeValidNumber', { fieldName })
24
+ };
25
+ }
26
+
27
+ if (numValue < min) {
28
+ return {
29
+ isValid: false,
30
+ value: min,
31
+ error: t('mustBeAtLeast', { fieldName, min })
32
+ };
33
+ }
34
+
35
+ if (numValue > max) {
36
+ return {
37
+ isValid: false,
38
+ value: max,
39
+ error: t('mustBeAtMost', { fieldName, max })
40
+ };
41
+ }
42
+
43
+ return {
44
+ isValid: true,
45
+ value: numValue,
46
+ error: null
47
+ };
48
+ };
49
+
50
+ /**
51
+ * Validate a timeout/duration value (in milliseconds)
52
+ * @param {number} value - Timeout value in ms
53
+ * @param {number} minMs - Minimum allowed timeout (default: from constants)
54
+ * @param {number} maxMs - Maximum allowed timeout (default: from constants)
55
+ * @returns {object} { isValid: boolean, value: number, error: string|null }
56
+ */
57
+ window.Validators.validateTimeout = function(value, minMs = null, maxMs = null) {
58
+ const { TIMEOUT_MIN, TIMEOUT_MAX } = window.AppConstants.VALIDATION;
59
+ return window.Validators.validateRange(value, minMs ?? TIMEOUT_MIN, maxMs ?? TIMEOUT_MAX, 'Timeout');
60
+ };
61
+
62
+ /**
63
+ * Validate and sanitize input with custom validator
64
+ * @param {any} value - Value to validate
65
+ * @param {Function} validator - Validator function
66
+ * @param {boolean} showError - Whether to show error toast (default: true)
67
+ * @returns {object} Validation result
68
+ */
69
+ window.Validators.validate = function(value, validator, showError = true) {
70
+ const result = validator(value);
71
+
72
+ if (!result.isValid && showError && result.error) {
73
+ window.ErrorHandler.showError(result.error);
74
+ }
75
+
76
+ return result;
77
+ };
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Utility functions for Antigravity Console
3
+ */
4
+
5
+ window.utils = {
6
+ // Shared Request Wrapper
7
+ async request(url, options = {}, webuiPassword = '') {
8
+ options.headers = options.headers || {};
9
+ if (webuiPassword) {
10
+ options.headers['x-webui-password'] = webuiPassword;
11
+ }
12
+
13
+ let response = await fetch(url, options);
14
+
15
+ if (response.status === 401) {
16
+ const store = Alpine.store('global');
17
+ const password = prompt(store ? store.t('enterPassword') : 'Enter Web UI Password:');
18
+ if (password) {
19
+ // Return new password so caller can update state
20
+ // This implies we need a way to propagate the new password back
21
+ // For simplicity in this functional utility, we might need a callback or state access
22
+ // But generally utils shouldn't probably depend on global state directly if possible
23
+ // let's stick to the current logic but wrapped
24
+ localStorage.setItem('commons_webui_password', password);
25
+ options.headers['x-webui-password'] = password;
26
+ response = await fetch(url, options);
27
+ return { response, newPassword: password };
28
+ }
29
+ }
30
+
31
+ return { response, newPassword: null };
32
+ },
33
+
34
+ formatTimeUntil(isoTime) {
35
+ const store = Alpine.store('global');
36
+ const diff = new Date(isoTime) - new Date();
37
+ if (diff <= 0) return store ? store.t('ready') : 'READY';
38
+ const mins = Math.floor(diff / 60000);
39
+ const hrs = Math.floor(mins / 60);
40
+
41
+ const hSuffix = store ? store.t('timeH') : 'H';
42
+ const mSuffix = store ? store.t('timeM') : 'M';
43
+
44
+ if (hrs > 0) return `${hrs}${hSuffix} ${mins % 60}${mSuffix}`;
45
+ return `${mins}${mSuffix}`;
46
+ },
47
+
48
+ getThemeColor(name) {
49
+ return getComputedStyle(document.documentElement).getPropertyValue(name).trim();
50
+ },
51
+
52
+ /**
53
+ * Debounce function - delays execution until after specified wait time
54
+ * @param {Function} func - Function to debounce
55
+ * @param {number} wait - Wait time in milliseconds
56
+ * @returns {Function} Debounced function
57
+ */
58
+ debounce(func, wait) {
59
+ let timeout;
60
+ return function executedFunction(...args) {
61
+ const later = () => {
62
+ clearTimeout(timeout);
63
+ func(...args);
64
+ };
65
+ clearTimeout(timeout);
66
+ timeout = setTimeout(later, wait);
67
+ };
68
+ }
69
+ };
Binary file