Skip to content

Commit eefb39d

Browse files
STetsingyann300
authored andcommitted
adding logs
1 parent 8b242d9 commit eefb39d

File tree

6 files changed

+126
-10
lines changed

6 files changed

+126
-10
lines changed

libs/remix-ai-core/src/inferencers/remote/remoteInference.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class RemoteInferencer implements ICompletions, IGeneration {
2626
const requestURL = rType === AIRequestType.COMPLETION ? this.completion_url : this.api_url
2727

2828
try {
29-
const options = { headers: { 'Content-Type': 'application/json', }, timeout: 2000 }
29+
const options = { headers: { 'Content-Type': 'application/json', }, timeout: 3000 }
3030
const result = await axios.post(requestURL, payload, options)
3131

3232
switch (rType) {

libs/remix-ui/editor/src/lib/inlineCompetionsLibs/AdaptiveRateLimiter.ts

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,26 +52,44 @@ export class AdaptiveRateLimiter {
5252
shouldAllowRequest(currentTime: number = Date.now()): boolean {
5353
const timeSinceLastRequest = currentTime - this.lastRequestTime;
5454
const timeSinceLastCompletion = currentTime - this.lastCompletionTime;
55+
const adaptiveCooldown = this.getAdaptiveCooldown();
56+
57+
const minIntervalCheck = timeSinceLastRequest < this.minRequestInterval;
58+
const adaptiveCooldownCheck = timeSinceLastCompletion < adaptiveCooldown;
59+
60+
console.log('[AdaptiveRateLimiter] shouldAllowRequest check:', {
61+
timeSinceLastRequest,
62+
timeSinceLastCompletion,
63+
minRequestInterval: this.minRequestInterval,
64+
adaptiveCooldown,
65+
acceptanceRate: this.acceptanceRate,
66+
minIntervalCheck,
67+
adaptiveCooldownCheck
68+
});
5569

5670
// Check minimum request interval
57-
if (timeSinceLastRequest < this.minRequestInterval) {
71+
if (minIntervalCheck) {
72+
console.log('[AdaptiveRateLimiter] Blocked: minimum request interval not met');
5873
return false;
5974
}
6075

6176
// Check adaptive cooldown
62-
const adaptiveCooldown = this.getAdaptiveCooldown();
63-
if (timeSinceLastCompletion < adaptiveCooldown) {
77+
if (adaptiveCooldownCheck) {
78+
console.log('[AdaptiveRateLimiter] Blocked: adaptive cooldown active');
6479
return false;
6580
}
6681

82+
console.log('[AdaptiveRateLimiter] Request allowed');
6783
return true;
6884
}
6985

7086
recordRequest(currentTime: number = Date.now()): void {
87+
console.log('[AdaptiveRateLimiter] Recording request at:', currentTime);
7188
this.lastRequestTime = currentTime;
7289
}
7390

7491
recordCompletion(currentTime: number = Date.now()): void {
92+
console.log('[AdaptiveRateLimiter] Recording completion at:', currentTime);
7593
this.lastCompletionTime = currentTime;
7694
}
7795

@@ -81,6 +99,7 @@ export class AdaptiveRateLimiter {
8199
timestamp: Date.now(),
82100
accepted: false
83101
});
102+
console.log('[AdaptiveRateLimiter] Completion shown, total:', this.totalCompletions);
84103
}
85104

86105
trackCompletionAccepted(): void {
@@ -90,10 +109,13 @@ export class AdaptiveRateLimiter {
90109
if (this.recentCompletionHistory.length > 0) {
91110
this.recentCompletionHistory[this.recentCompletionHistory.length - 1].accepted = true;
92111
}
112+
113+
console.log('[AdaptiveRateLimiter] Completion accepted, total accepted:', this.acceptedCompletions);
93114
}
94115

95116
trackCompletionRejected(): void {
96117
this.rejectedCompletions++;
118+
console.log('[AdaptiveRateLimiter] Completion rejected, total rejected:', this.rejectedCompletions);
97119
}
98120

99121
private getAdaptiveCooldown(): number {
@@ -111,6 +133,7 @@ export class AdaptiveRateLimiter {
111133

112134
private updateAcceptanceRate(): void {
113135
const currentTime = Date.now();
136+
const oldHistoryLength = this.recentCompletionHistory.length;
114137

115138
// Remove old entries beyond the history window
116139
this.recentCompletionHistory = this.recentCompletionHistory.filter(
@@ -126,6 +149,12 @@ export class AdaptiveRateLimiter {
126149
// do not penalize anyone at startup
127150
this.acceptanceRate = 0.5;
128151
}
152+
153+
console.log('[AdaptiveRateLimiter] Acceptance rate updated:', {
154+
oldHistoryLength,
155+
newHistoryLength: this.recentCompletionHistory.length,
156+
acceptanceRate: this.acceptanceRate
157+
});
129158
}
130159

131160
getStats(): AdaptiveRateLimiterStats {

libs/remix-ui/editor/src/lib/inlineCompetionsLibs/CompletionCache.ts

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,36 @@ export class CompletionCache {
5151
*/
5252
getCachedResult(cacheKey: string): any | null {
5353
const cached = this.cache.get(cacheKey);
54-
if (cached && Date.now() - cached.timestamp < this.cacheTimeout) {
54+
const currentTime = Date.now();
55+
const isExpired = cached && currentTime - cached.timestamp >= this.cacheTimeout;
56+
57+
console.log('[CompletionCache] getCachedResult:', {
58+
cacheKey: cacheKey.substring(0, 50) + '...',
59+
hasCached: !!cached,
60+
isExpired,
61+
age: cached ? currentTime - cached.timestamp : 0
62+
});
63+
64+
if (cached && !isExpired) {
65+
console.log('[CompletionCache] Cache hit');
5566
return cached.result;
5667
}
5768

5869
// Remove expired cache entry
5970
if (cached) {
71+
console.log('[CompletionCache] Removing expired cache entry');
6072
this.cache.delete(cacheKey);
6173
}
6274

75+
console.log('[CompletionCache] Cache miss');
6376
return null;
6477
}
6578

6679
/**
6780
* Cache a completion result
6881
*/
6982
cacheResult(cacheKey: string, result: any): void {
83+
const oldSize = this.cache.size;
7084
// Clean up old cache entries periodically
7185
if (this.cache.size >= this.maxCacheSize) {
7286
this.cleanupExpiredEntries();
@@ -76,6 +90,7 @@ export class CompletionCache {
7690
if (this.cache.size >= this.maxCacheSize) {
7791
const oldestKey = this.cache.keys().next().value;
7892
if (oldestKey) {
93+
console.log('[CompletionCache] Removing oldest cache entry due to capacity');
7994
this.cache.delete(oldestKey);
8095
}
8196
}
@@ -84,13 +99,24 @@ export class CompletionCache {
8499
result: result,
85100
timestamp: Date.now()
86101
});
102+
103+
console.log('[CompletionCache] Cached result:', {
104+
cacheKey: cacheKey.substring(0, 50) + '...',
105+
oldSize,
106+
newSize: this.cache.size
107+
});
87108
}
88109

89110
/**
90111
* Check if a request is already pending
91112
*/
92113
isPending(cacheKey: string): boolean {
93-
return this.pendingRequests.has(cacheKey);
114+
const pending = this.pendingRequests.has(cacheKey);
115+
console.log('[CompletionCache] isPending:', {
116+
cacheKey: cacheKey.substring(0, 50) + '...',
117+
pending
118+
});
119+
return pending;
94120
}
95121

96122
/**
@@ -104,13 +130,21 @@ export class CompletionCache {
104130
* Set a pending request
105131
*/
106132
setPendingRequest(cacheKey: string, promise: Promise<any>): void {
133+
console.log('[CompletionCache] Setting pending request:', {
134+
cacheKey: cacheKey.substring(0, 50) + '...',
135+
totalPending: this.pendingRequests.size + 1
136+
});
107137
this.pendingRequests.set(cacheKey, promise);
108138
}
109139

110140
/**
111141
* Remove a pending request
112142
*/
113143
removePendingRequest(cacheKey: string): void {
144+
console.log('[CompletionCache] Removing pending request:', {
145+
cacheKey: cacheKey.substring(0, 50) + '...',
146+
totalPending: this.pendingRequests.size - 1
147+
});
114148
this.pendingRequests.delete(cacheKey);
115149
}
116150

@@ -121,26 +155,37 @@ export class CompletionCache {
121155
cacheKey: string,
122156
requestFn: () => Promise<T>
123157
): Promise<T> {
158+
console.log('[CompletionCache] handleRequest started:', {
159+
cacheKey: cacheKey.substring(0, 50) + '...'
160+
});
161+
124162
// Check cache first
125163
const cachedResult = this.getCachedResult(cacheKey);
126164
if (cachedResult) {
165+
console.log('[CompletionCache] Returning cached result');
127166
return cachedResult;
128167
}
129168

130169
// Check if same request is already pending
131170
const pendingRequest = this.getPendingRequest(cacheKey);
132171
if (pendingRequest) {
172+
console.log('[CompletionCache] Waiting for pending request');
133173
return await pendingRequest;
134174
}
135175

136176
// Create and store pending request
177+
console.log('[CompletionCache] Creating new request');
137178
const promise = requestFn();
138179
this.setPendingRequest(cacheKey, promise);
139180

140181
try {
141182
const result = await promise;
183+
console.log('[CompletionCache] Request completed successfully');
142184
this.cacheResult(cacheKey, result);
143185
return result;
186+
} catch (error) {
187+
console.error('[CompletionCache] Request failed:', error);
188+
throw error;
144189
} finally {
145190
this.removePendingRequest(cacheKey);
146191
}
@@ -156,6 +201,7 @@ export class CompletionCache {
156201
}
157202

158203
clear(): void {
204+
console.log('[CompletionCache] Clearing cache and pending requests');
159205
this.cache.clear();
160206
this.pendingRequests.clear();
161207
}
@@ -169,6 +215,12 @@ export class CompletionCache {
169215
}
170216

171217
cleanup(): void {
218+
const oldSize = this.cache.size;
172219
this.cleanupExpiredEntries();
220+
console.log('[CompletionCache] Cleanup completed:', {
221+
oldSize,
222+
newSize: this.cache.size,
223+
removedEntries: oldSize - this.cache.size
224+
});
173225
}
174226
}

libs/remix-ui/editor/src/lib/inlineCompetionsLibs/SmartContextDetector.ts

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,32 @@ export class SmartContextDetector {
4545
): boolean {
4646
this.updateTypingSpeed(currentTime);
4747

48-
if (this.isRapidTyping(currentTime)) return false;
49-
if (this.isInStringOrComment(model, position)) return false;
50-
if (!this.isAppropriatePosition(model, position)) return false;
48+
const rapidTyping = this.isRapidTyping(currentTime);
49+
const inStringOrComment = this.isInStringOrComment(model, position);
50+
const appropriatePosition = this.isAppropriatePosition(model, position);
51+
52+
console.log('[SmartContextDetector] shouldShowCompletion check:', {
53+
rapidTyping,
54+
inStringOrComment,
55+
appropriatePosition,
56+
typingSpeed: this.typingSpeed,
57+
timeSinceLastTyping: currentTime - this.lastTypingTime
58+
});
59+
60+
if (rapidTyping) {
61+
console.log('[SmartContextDetector] Blocked: rapid typing detected');
62+
return false;
63+
}
64+
if (inStringOrComment) {
65+
console.log('[SmartContextDetector] Blocked: in string or comment');
66+
return false;
67+
}
68+
if (!appropriatePosition) {
69+
console.log('[SmartContextDetector] Blocked: inappropriate position');
70+
return false;
71+
}
5172

73+
console.log('[SmartContextDetector] Completion allowed');
5274
return true;
5375
}
5476

@@ -69,6 +91,12 @@ export class SmartContextDetector {
6991
const avgSpeed = this.typingSpeedWindow.reduce((sum, entry) => sum + entry.speed, 0) / this.typingSpeedWindow.length;
7092
this.typingSpeed = avgSpeed;
7193
}
94+
95+
console.log('[SmartContextDetector] Typing speed updated:', {
96+
timeDiff,
97+
avgSpeed: this.typingSpeed,
98+
windowSize: this.typingSpeedWindow.length
99+
});
72100
}
73101
this.lastTypingTime = currentTime;
74102
}
@@ -152,6 +180,7 @@ export class SmartContextDetector {
152180
}
153181

154182
reset(): void {
183+
console.log('[SmartContextDetector] Resetting state');
155184
this.typingSpeed = 0;
156185
this.lastTypingTime = 0;
157186
this.typingSpeedWindow = [];

libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli
3030
item: [],
3131
task: this.task,
3232
displayed: false,
33-
accepted: false
33+
accepted: false,
34+
onAccepted: () => {
35+
this.rateLimiter.trackCompletionAccepted()
36+
}
3437
}
3538

3639
this.rateLimiter = new AdaptiveRateLimiter();
@@ -101,6 +104,7 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli
101104

102105
// Create cache key and check cache
103106
const cacheKey = this.cache.createCacheKey(word, word_after, position, this.task);
107+
this.currentCompletion.accepted = false
104108

105109
return await this.cache.handleRequest(cacheKey, async () => {
106110
return await this.performCompletion(word, word_after, position);

libs/remix-ui/editor/src/lib/remix-ui-editor.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,8 @@ export const EditorUI = (props: EditorUIProps) => {
838838
const changes = e.changes;
839839
// Check if the change matches the current completion
840840
if (changes.some(change => change.text === inlineCompletionProvider.currentCompletion.item.insertText)) {
841+
inlineCompletionProvider.currentCompletion.onAccepted()
842+
inlineCompletionProvider.currentCompletion.accepted = true
841843
_paq.push(['trackEvent', 'ai', 'remixAI', inlineCompletionProvider.currentCompletion.task + '_accepted'])
842844
}
843845
}

0 commit comments

Comments
 (0)