vibecodingmachine-core 2026.3.9-907 → 2026.3.10-1548
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/package.json +1 -1
- package/src/auth/access-denied.html +119 -119
- package/src/auth/shared-auth-storage.js +267 -267
- package/src/autonomous-mode/feature-implementer.cjs +70 -70
- package/src/autonomous-mode/feature-implementer.js +425 -425
- package/src/beta-request.js +160 -160
- package/src/chat-management/chat-manager.cjs +71 -71
- package/src/chat-management/chat-manager.js +342 -342
- package/src/compliance/compliance-prompt.js +183 -183
- package/src/ide-integration/aider-cli-manager.cjs +850 -850
- package/src/ide-integration/applescript-manager.cjs +3215 -3215
- package/src/ide-integration/applescript-utils.js +314 -314
- package/src/ide-integration/cdp-manager.cjs +221 -221
- package/src/ide-integration/claude-code-cli-manager.cjs +456 -456
- package/src/ide-integration/cline-cli-manager.cjs +2252 -2252
- package/src/ide-integration/continue-cli-manager.js +431 -431
- package/src/ide-integration/provider-manager.cjs +595 -595
- package/src/ide-integration/quota-detector.cjs +399 -399
- package/src/ide-integration/windows-automation-manager.js +532 -4
- package/src/ide-integration/windows-ide-manager.js +12 -3
- package/src/index.cjs +142 -142
- package/src/llm/direct-llm-manager.cjs +1299 -1299
- package/src/localization/index.js +147 -147
- package/src/quota-management/index.js +108 -108
- package/src/requirement-numbering.js +164 -164
- package/src/sync/aws-setup.js +445 -445
- package/src/ui/ButtonComponents.js +247 -247
- package/src/ui/ChatInterface.js +499 -499
- package/src/ui/StateManager.js +259 -259
- package/src/utils/audit-logger.cjs +116 -116
- package/src/utils/config-helpers.cjs +94 -94
- package/src/utils/config-helpers.js +94 -94
- package/src/utils/env-helpers.js +54 -54
- package/src/utils/error-reporter.js +117 -117
- package/src/utils/gcloud-auth.cjs +394 -394
- package/src/utils/git-branch-manager.js +278 -278
- package/src/utils/logger.cjs +193 -193
- package/src/utils/logger.js +191 -191
- package/src/utils/repo-helpers.cjs +120 -120
- package/src/utils/repo-helpers.js +120 -120
- package/src/utils/update-checker.js +246 -246
- package/src/utils/version-checker.js +170 -170
|
@@ -1,148 +1,148 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared Localization System for Vibe Coding Machine
|
|
3
|
-
* Used by both CLI and GUI applications
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
const os = require('os');
|
|
7
|
-
|
|
8
|
-
// Supported locales
|
|
9
|
-
const SUPPORTED_LOCALES = ['en', 'es'];
|
|
10
|
-
const DEFAULT_LOCALE = 'en';
|
|
11
|
-
|
|
12
|
-
// Language names mapping
|
|
13
|
-
const LANGUAGE_NAMES = {
|
|
14
|
-
'en': 'English',
|
|
15
|
-
'es': 'Spanish'
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Get supported language names
|
|
20
|
-
* @returns {Object} Object mapping locale codes to language names
|
|
21
|
-
*/
|
|
22
|
-
function getSupportedLanguageNames() {
|
|
23
|
-
return { ...LANGUAGE_NAMES };
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Get language display name
|
|
28
|
-
* @param {string} languageCode - Language code
|
|
29
|
-
* @returns {string} Display name for the language
|
|
30
|
-
*/
|
|
31
|
-
function getLanguageDisplayName(languageCode) {
|
|
32
|
-
if (!languageCode) return 'Not Set';
|
|
33
|
-
return LANGUAGE_NAMES[languageCode] || languageCode;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Check if a language is supported
|
|
38
|
-
* @param {string} languageCode - Language code to check
|
|
39
|
-
* @returns {boolean} True if language is supported
|
|
40
|
-
*/
|
|
41
|
-
function isLanguageSupported(languageCode) {
|
|
42
|
-
return SUPPORTED_LOCALES.includes(languageCode);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Detect user's preferred locale
|
|
47
|
-
* @returns {string} Locale code (e.g., 'en', 'es')
|
|
48
|
-
*/
|
|
49
|
-
function detectLocale() {
|
|
50
|
-
// Check environment variables first
|
|
51
|
-
const envLocale = process.env.LANG || process.env.LC_ALL || process.env.LC_MESSAGES;
|
|
52
|
-
if (envLocale) {
|
|
53
|
-
const locale = envLocale.split('.')[0].split('_')[0].toLowerCase();
|
|
54
|
-
if (SUPPORTED_LOCALES.includes(locale)) {
|
|
55
|
-
return locale;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Check system locale (Node.js)
|
|
60
|
-
try {
|
|
61
|
-
const systemLocale = Intl.DateTimeFormat().resolvedOptions().locale;
|
|
62
|
-
const locale = systemLocale.split('-')[0].toLowerCase();
|
|
63
|
-
if (SUPPORTED_LOCALES.includes(locale)) {
|
|
64
|
-
return locale;
|
|
65
|
-
}
|
|
66
|
-
} catch (error) {
|
|
67
|
-
// Fallback if Intl is not available
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return DEFAULT_LOCALE;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Get current locale
|
|
75
|
-
* @returns {string} Current locale
|
|
76
|
-
*/
|
|
77
|
-
function getCurrentLocale() {
|
|
78
|
-
return global._vibecodingmachine_locale || detectLocale();
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Set current locale
|
|
83
|
-
* @param {string} locale - Locale to set
|
|
84
|
-
*/
|
|
85
|
-
function setLocale(locale) {
|
|
86
|
-
if (SUPPORTED_LOCALES.includes(locale)) {
|
|
87
|
-
global._vibecodingmachine_locale = locale;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Translate a text string
|
|
93
|
-
* @param {string} key - Translation key
|
|
94
|
-
* @param {Object} params - Parameters for interpolation
|
|
95
|
-
* @returns {string} Translated text
|
|
96
|
-
*/
|
|
97
|
-
function t(key, params = {}) {
|
|
98
|
-
const locale = getCurrentLocale();
|
|
99
|
-
const translations = getTranslations(locale);
|
|
100
|
-
|
|
101
|
-
let text = translations[key] || key;
|
|
102
|
-
|
|
103
|
-
// Simple parameter interpolation
|
|
104
|
-
if (params && typeof params === 'object') {
|
|
105
|
-
Object.keys(params).forEach(param => {
|
|
106
|
-
text = text.replace(new RegExp(`\\{${param}\\}`, 'g'), params[param]);
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return text;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Get translations for a specific locale
|
|
115
|
-
* @param {string} locale - Locale code
|
|
116
|
-
* @returns {Object} Translation object
|
|
117
|
-
*/
|
|
118
|
-
function getTranslations(locale) {
|
|
119
|
-
switch (locale) {
|
|
120
|
-
case 'es':
|
|
121
|
-
return require('./translations/es');
|
|
122
|
-
case 'en':
|
|
123
|
-
default:
|
|
124
|
-
return require('./translations/en');
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Get available locales
|
|
130
|
-
* @returns {Array} Array of supported locale codes
|
|
131
|
-
*/
|
|
132
|
-
function getAvailableLocales() {
|
|
133
|
-
return [...SUPPORTED_LOCALES];
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
module.exports = {
|
|
137
|
-
t,
|
|
138
|
-
getCurrentLocale,
|
|
139
|
-
setLocale,
|
|
140
|
-
detectLocale,
|
|
141
|
-
getAvailableLocales,
|
|
142
|
-
getSupportedLanguageNames,
|
|
143
|
-
getLanguageDisplayName,
|
|
144
|
-
isLanguageSupported,
|
|
145
|
-
SUPPORTED_LOCALES,
|
|
146
|
-
DEFAULT_LOCALE,
|
|
147
|
-
LANGUAGE_NAMES
|
|
1
|
+
/**
|
|
2
|
+
* Shared Localization System for Vibe Coding Machine
|
|
3
|
+
* Used by both CLI and GUI applications
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const os = require('os');
|
|
7
|
+
|
|
8
|
+
// Supported locales
|
|
9
|
+
const SUPPORTED_LOCALES = ['en', 'es'];
|
|
10
|
+
const DEFAULT_LOCALE = 'en';
|
|
11
|
+
|
|
12
|
+
// Language names mapping
|
|
13
|
+
const LANGUAGE_NAMES = {
|
|
14
|
+
'en': 'English',
|
|
15
|
+
'es': 'Spanish'
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Get supported language names
|
|
20
|
+
* @returns {Object} Object mapping locale codes to language names
|
|
21
|
+
*/
|
|
22
|
+
function getSupportedLanguageNames() {
|
|
23
|
+
return { ...LANGUAGE_NAMES };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Get language display name
|
|
28
|
+
* @param {string} languageCode - Language code
|
|
29
|
+
* @returns {string} Display name for the language
|
|
30
|
+
*/
|
|
31
|
+
function getLanguageDisplayName(languageCode) {
|
|
32
|
+
if (!languageCode) return 'Not Set';
|
|
33
|
+
return LANGUAGE_NAMES[languageCode] || languageCode;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Check if a language is supported
|
|
38
|
+
* @param {string} languageCode - Language code to check
|
|
39
|
+
* @returns {boolean} True if language is supported
|
|
40
|
+
*/
|
|
41
|
+
function isLanguageSupported(languageCode) {
|
|
42
|
+
return SUPPORTED_LOCALES.includes(languageCode);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Detect user's preferred locale
|
|
47
|
+
* @returns {string} Locale code (e.g., 'en', 'es')
|
|
48
|
+
*/
|
|
49
|
+
function detectLocale() {
|
|
50
|
+
// Check environment variables first
|
|
51
|
+
const envLocale = process.env.LANG || process.env.LC_ALL || process.env.LC_MESSAGES;
|
|
52
|
+
if (envLocale) {
|
|
53
|
+
const locale = envLocale.split('.')[0].split('_')[0].toLowerCase();
|
|
54
|
+
if (SUPPORTED_LOCALES.includes(locale)) {
|
|
55
|
+
return locale;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Check system locale (Node.js)
|
|
60
|
+
try {
|
|
61
|
+
const systemLocale = Intl.DateTimeFormat().resolvedOptions().locale;
|
|
62
|
+
const locale = systemLocale.split('-')[0].toLowerCase();
|
|
63
|
+
if (SUPPORTED_LOCALES.includes(locale)) {
|
|
64
|
+
return locale;
|
|
65
|
+
}
|
|
66
|
+
} catch (error) {
|
|
67
|
+
// Fallback if Intl is not available
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return DEFAULT_LOCALE;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Get current locale
|
|
75
|
+
* @returns {string} Current locale
|
|
76
|
+
*/
|
|
77
|
+
function getCurrentLocale() {
|
|
78
|
+
return global._vibecodingmachine_locale || detectLocale();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Set current locale
|
|
83
|
+
* @param {string} locale - Locale to set
|
|
84
|
+
*/
|
|
85
|
+
function setLocale(locale) {
|
|
86
|
+
if (SUPPORTED_LOCALES.includes(locale)) {
|
|
87
|
+
global._vibecodingmachine_locale = locale;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Translate a text string
|
|
93
|
+
* @param {string} key - Translation key
|
|
94
|
+
* @param {Object} params - Parameters for interpolation
|
|
95
|
+
* @returns {string} Translated text
|
|
96
|
+
*/
|
|
97
|
+
function t(key, params = {}) {
|
|
98
|
+
const locale = getCurrentLocale();
|
|
99
|
+
const translations = getTranslations(locale);
|
|
100
|
+
|
|
101
|
+
let text = translations[key] || key;
|
|
102
|
+
|
|
103
|
+
// Simple parameter interpolation
|
|
104
|
+
if (params && typeof params === 'object') {
|
|
105
|
+
Object.keys(params).forEach(param => {
|
|
106
|
+
text = text.replace(new RegExp(`\\{${param}\\}`, 'g'), params[param]);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return text;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Get translations for a specific locale
|
|
115
|
+
* @param {string} locale - Locale code
|
|
116
|
+
* @returns {Object} Translation object
|
|
117
|
+
*/
|
|
118
|
+
function getTranslations(locale) {
|
|
119
|
+
switch (locale) {
|
|
120
|
+
case 'es':
|
|
121
|
+
return require('./translations/es');
|
|
122
|
+
case 'en':
|
|
123
|
+
default:
|
|
124
|
+
return require('./translations/en');
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Get available locales
|
|
130
|
+
* @returns {Array} Array of supported locale codes
|
|
131
|
+
*/
|
|
132
|
+
function getAvailableLocales() {
|
|
133
|
+
return [...SUPPORTED_LOCALES];
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
module.exports = {
|
|
137
|
+
t,
|
|
138
|
+
getCurrentLocale,
|
|
139
|
+
setLocale,
|
|
140
|
+
detectLocale,
|
|
141
|
+
getAvailableLocales,
|
|
142
|
+
getSupportedLanguageNames,
|
|
143
|
+
getLanguageDisplayName,
|
|
144
|
+
isLanguageSupported,
|
|
145
|
+
SUPPORTED_LOCALES,
|
|
146
|
+
DEFAULT_LOCALE,
|
|
147
|
+
LANGUAGE_NAMES
|
|
148
148
|
};
|
|
@@ -1,108 +1,108 @@
|
|
|
1
|
-
const sharedAuth = require('../auth/shared-auth-storage');
|
|
2
|
-
const ProviderManager = require('../ide-integration/provider-manager.cjs');
|
|
3
|
-
|
|
4
|
-
// In-memory cache for quota data.
|
|
5
|
-
const quotaCache = new Map();
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Represents the quota details for a specific agent.
|
|
9
|
-
*/
|
|
10
|
-
class Quota {
|
|
11
|
-
/**
|
|
12
|
-
* @param {string} agentId - The unique identifier for the agent (e.g., 'openai:gpt-4').
|
|
13
|
-
* @param {number} limit - The total quota limit.
|
|
14
|
-
* @param {number} remaining - The remaining quota.
|
|
15
|
-
* @param {Date} resetsAt - The timestamp when the quota resets.
|
|
16
|
-
* @param {string} type - The type of quota ('global', 'rate-limit', 'infinite').
|
|
17
|
-
*/
|
|
18
|
-
constructor(agentId, limit, remaining, resetsAt, type = 'rate-limit') {
|
|
19
|
-
this.agentId = agentId;
|
|
20
|
-
this.limit = limit;
|
|
21
|
-
this.remaining = remaining;
|
|
22
|
-
this.resetsAt = resetsAt;
|
|
23
|
-
this.lastUpdated = new Date();
|
|
24
|
-
this.type = type;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Checks if the quota has been exceeded.
|
|
29
|
-
* @returns {boolean} True if the remaining quota is zero or less.
|
|
30
|
-
*/
|
|
31
|
-
isExceeded() {
|
|
32
|
-
return this.remaining <= 0;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Fetches quota information for a given agent.
|
|
38
|
-
*
|
|
39
|
-
* @param {string} agentId - The ID of the agent to fetch quota for (e.g., 'anthropic:claude-3').
|
|
40
|
-
* @returns {Promise<Quota>} A promise that resolves to a Quota object.
|
|
41
|
-
*/
|
|
42
|
-
async function fetchQuotaForAgent(agentId) {
|
|
43
|
-
// 1. Handle Global Daily Iteration Quota
|
|
44
|
-
if (agentId === 'global:iterations') {
|
|
45
|
-
const quotaInfo = await sharedAuth.canRunAutoMode();
|
|
46
|
-
const today = new Date();
|
|
47
|
-
const tonight = new Date(today);
|
|
48
|
-
tonight.setHours(24, 0, 0, 0);
|
|
49
|
-
|
|
50
|
-
const quota = new Quota(
|
|
51
|
-
'global:iterations',
|
|
52
|
-
quotaInfo.maxIterations || 10,
|
|
53
|
-
quotaInfo.todayUsage !== undefined ? Math.max(0, (quotaInfo.maxIterations || 10) - quotaInfo.todayUsage) : 10,
|
|
54
|
-
tonight,
|
|
55
|
-
'global'
|
|
56
|
-
);
|
|
57
|
-
quotaCache.set(agentId, quota);
|
|
58
|
-
return quota;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// 2. Handle Local Agent (Infinite Quota)
|
|
62
|
-
if (agentId.startsWith('local-') || agentId.includes('ollama')) {
|
|
63
|
-
const quota = new Quota(agentId, Infinity, Infinity, null, 'infinite');
|
|
64
|
-
quotaCache.set(agentId, quota);
|
|
65
|
-
return quota;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// 3. Handle Provider Rate Limits via ProviderManager
|
|
69
|
-
try {
|
|
70
|
-
const providerManager = new ProviderManager();
|
|
71
|
-
const parts = agentId.split(':');
|
|
72
|
-
const provider = parts[0];
|
|
73
|
-
const model = parts[1] || provider;
|
|
74
|
-
|
|
75
|
-
const isLimited = providerManager.isRateLimited(provider, model);
|
|
76
|
-
const timeUntilReset = providerManager.getTimeUntilReset(provider, model);
|
|
77
|
-
|
|
78
|
-
const quota = new Quota(
|
|
79
|
-
agentId,
|
|
80
|
-
1, // Binary limit for rate limits (1 if available, 0 if limited)
|
|
81
|
-
isLimited ? 0 : 1,
|
|
82
|
-
timeUntilReset ? new Date(Date.now() + timeUntilReset) : null,
|
|
83
|
-
'rate-limit'
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
quotaCache.set(agentId, quota);
|
|
87
|
-
return quota;
|
|
88
|
-
} catch (error) {
|
|
89
|
-
console.error(`Error fetching provider quota for ${agentId}:`, error);
|
|
90
|
-
return new Quota(agentId, 1, 1, null, 'rate-limit');
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Retrieves the cached quota for a given agent.
|
|
96
|
-
*
|
|
97
|
-
* @param {string} agentId - The ID of the agent.
|
|
98
|
-
* @returns {Quota | undefined} The cached Quota object or undefined if not found.
|
|
99
|
-
*/
|
|
100
|
-
function getCachedQuota(agentId) {
|
|
101
|
-
return quotaCache.get(agentId);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
module.exports = {
|
|
105
|
-
Quota,
|
|
106
|
-
fetchQuotaForAgent,
|
|
107
|
-
getCachedQuota,
|
|
108
|
-
};
|
|
1
|
+
const sharedAuth = require('../auth/shared-auth-storage');
|
|
2
|
+
const ProviderManager = require('../ide-integration/provider-manager.cjs');
|
|
3
|
+
|
|
4
|
+
// In-memory cache for quota data.
|
|
5
|
+
const quotaCache = new Map();
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Represents the quota details for a specific agent.
|
|
9
|
+
*/
|
|
10
|
+
class Quota {
|
|
11
|
+
/**
|
|
12
|
+
* @param {string} agentId - The unique identifier for the agent (e.g., 'openai:gpt-4').
|
|
13
|
+
* @param {number} limit - The total quota limit.
|
|
14
|
+
* @param {number} remaining - The remaining quota.
|
|
15
|
+
* @param {Date} resetsAt - The timestamp when the quota resets.
|
|
16
|
+
* @param {string} type - The type of quota ('global', 'rate-limit', 'infinite').
|
|
17
|
+
*/
|
|
18
|
+
constructor(agentId, limit, remaining, resetsAt, type = 'rate-limit') {
|
|
19
|
+
this.agentId = agentId;
|
|
20
|
+
this.limit = limit;
|
|
21
|
+
this.remaining = remaining;
|
|
22
|
+
this.resetsAt = resetsAt;
|
|
23
|
+
this.lastUpdated = new Date();
|
|
24
|
+
this.type = type;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Checks if the quota has been exceeded.
|
|
29
|
+
* @returns {boolean} True if the remaining quota is zero or less.
|
|
30
|
+
*/
|
|
31
|
+
isExceeded() {
|
|
32
|
+
return this.remaining <= 0;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Fetches quota information for a given agent.
|
|
38
|
+
*
|
|
39
|
+
* @param {string} agentId - The ID of the agent to fetch quota for (e.g., 'anthropic:claude-3').
|
|
40
|
+
* @returns {Promise<Quota>} A promise that resolves to a Quota object.
|
|
41
|
+
*/
|
|
42
|
+
async function fetchQuotaForAgent(agentId) {
|
|
43
|
+
// 1. Handle Global Daily Iteration Quota
|
|
44
|
+
if (agentId === 'global:iterations') {
|
|
45
|
+
const quotaInfo = await sharedAuth.canRunAutoMode();
|
|
46
|
+
const today = new Date();
|
|
47
|
+
const tonight = new Date(today);
|
|
48
|
+
tonight.setHours(24, 0, 0, 0);
|
|
49
|
+
|
|
50
|
+
const quota = new Quota(
|
|
51
|
+
'global:iterations',
|
|
52
|
+
quotaInfo.maxIterations || 10,
|
|
53
|
+
quotaInfo.todayUsage !== undefined ? Math.max(0, (quotaInfo.maxIterations || 10) - quotaInfo.todayUsage) : 10,
|
|
54
|
+
tonight,
|
|
55
|
+
'global'
|
|
56
|
+
);
|
|
57
|
+
quotaCache.set(agentId, quota);
|
|
58
|
+
return quota;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// 2. Handle Local Agent (Infinite Quota)
|
|
62
|
+
if (agentId.startsWith('local-') || agentId.includes('ollama')) {
|
|
63
|
+
const quota = new Quota(agentId, Infinity, Infinity, null, 'infinite');
|
|
64
|
+
quotaCache.set(agentId, quota);
|
|
65
|
+
return quota;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// 3. Handle Provider Rate Limits via ProviderManager
|
|
69
|
+
try {
|
|
70
|
+
const providerManager = new ProviderManager();
|
|
71
|
+
const parts = agentId.split(':');
|
|
72
|
+
const provider = parts[0];
|
|
73
|
+
const model = parts[1] || provider;
|
|
74
|
+
|
|
75
|
+
const isLimited = providerManager.isRateLimited(provider, model);
|
|
76
|
+
const timeUntilReset = providerManager.getTimeUntilReset(provider, model);
|
|
77
|
+
|
|
78
|
+
const quota = new Quota(
|
|
79
|
+
agentId,
|
|
80
|
+
1, // Binary limit for rate limits (1 if available, 0 if limited)
|
|
81
|
+
isLimited ? 0 : 1,
|
|
82
|
+
timeUntilReset ? new Date(Date.now() + timeUntilReset) : null,
|
|
83
|
+
'rate-limit'
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
quotaCache.set(agentId, quota);
|
|
87
|
+
return quota;
|
|
88
|
+
} catch (error) {
|
|
89
|
+
console.error(`Error fetching provider quota for ${agentId}:`, error);
|
|
90
|
+
return new Quota(agentId, 1, 1, null, 'rate-limit');
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Retrieves the cached quota for a given agent.
|
|
96
|
+
*
|
|
97
|
+
* @param {string} agentId - The ID of the agent.
|
|
98
|
+
* @returns {Quota | undefined} The cached Quota object or undefined if not found.
|
|
99
|
+
*/
|
|
100
|
+
function getCachedQuota(agentId) {
|
|
101
|
+
return quotaCache.get(agentId);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
module.exports = {
|
|
105
|
+
Quota,
|
|
106
|
+
fetchQuotaForAgent,
|
|
107
|
+
getCachedQuota,
|
|
108
|
+
};
|