Skip to content

Commit 0c445af

Browse files
authored
Merge pull request #6776 from remix-project-org/inlineCompl_update
resolving race condition issue and matomo logging
2 parents 32adbd9 + 5c7494e commit 0c445af

File tree

10 files changed

+206
-99
lines changed

10 files changed

+206
-99
lines changed

apps/remix-ide/src/app/plugins/remix-ai-assistant.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export class RemixAIAssistant extends ViewPlugin {
114114
async handleActivity(type: string, payload: any) {
115115
// Never log user prompts - only track the activity type
116116
const eventName = type === 'promptSend' ? 'remixai-assistant-promptSend' : `remixai-assistant-${type}-${payload}`;
117-
trackMatomoEvent(this, { category: 'ai', action: 'chatting', name: `${type}-${payload}`, isClick: true })
117+
trackMatomoEvent(this, { category: 'ai', action: 'remixAI', name: `chatting${type}-${payload}`, isClick: true })
118118
}
119119

120120
updateComponent(state: {

apps/remix-ide/src/app/plugins/remixAIPlugin.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ export class RemixAIPlugin extends Plugin {
197197
params.provider = 'anthropic' // enforce all generation to be only on anthropic
198198
params.model = 'claude-haiku-4-5'
199199
useRag = false
200-
trackMatomoEvent(this, { category: 'ai', action: 'GenerateNewAIWorkspace', name: 'GenerateNewAIWorkspace', isClick: false })
200+
trackMatomoEvent(this, { category: 'ai', action: 'remixAI', name: 'GenerateNewAIWorkspace', isClick: false })
201201
let userPrompt = ''
202202

203203
if (useRag) {
@@ -241,7 +241,7 @@ export class RemixAIPlugin extends Plugin {
241241
params.threadId = newThreadID
242242
params.provider = this.selectedModel.provider
243243
useRag = false
244-
trackMatomoEvent(this, { category: 'ai', action: 'GenerateNewAIWorkspace', name: 'WorkspaceAgentEdit', isClick: false })
244+
trackMatomoEvent(this, { category: 'ai', action: 'remixAI', name: 'WorkspaceAgentEdit', isClick: false })
245245

246246
await statusCallback?.('Performing workspace request...')
247247
if (useRag) {
@@ -308,7 +308,7 @@ export class RemixAIPlugin extends Plugin {
308308
else {
309309
console.log("chatRequestBuffer is not empty. First process the last request.", this.chatRequestBuffer)
310310
}
311-
trackMatomoEvent(this, { category: 'ai', action: 'chatting', name: 'remixAI_chat', isClick: false })
311+
trackMatomoEvent(this, { category: 'ai', action: 'remixAI', name: 'remixAI_chat', isClick: false })
312312
}
313313

314314
async ProcessChatRequestBuffer(params:IParams=GenerationParams){

libs/remix-ai-core/src/inferencers/mcp/mcpClient.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class MCPClient {
5151
async connect(): Promise<IMCPInitializeResult> {
5252
try {
5353
this.eventEmitter.emit('connecting', this.server.name);
54-
trackMatomoEvent('ai', 'mcp_connect_attempt', `${this.server.name}|${this.server.transport}`);
54+
trackMatomoEvent('ai', 'remixAI', `mcp_connect_attempt_${this.server.name}|${this.server.transport}`);
5555

5656
if (this.server.transport === 'internal') {
5757
return await this.connectInternal();
@@ -69,7 +69,7 @@ export class MCPClient {
6969

7070
} catch (error) {
7171
this.eventEmitter.emit('error', this.server.name, error);
72-
trackMatomoEvent('ai', 'mcp_connect_failed', `${this.server.name}|${error.message}`);
72+
trackMatomoEvent('ai', 'remixAI', `mcp_connect_failed_${this.server.name}|${error.message}`);
7373
throw error;
7474
}
7575
}
@@ -83,7 +83,7 @@ export class MCPClient {
8383
this.connected = true;
8484
this.capabilities = result.capabilities;
8585
this.eventEmitter.emit('connected', this.server.name, result);
86-
trackMatomoEvent('ai', 'mcp_connect_success', `${this.server.name}|internal`);
86+
trackMatomoEvent('ai', 'remixAI', `mcp_connect_success_${this.server.name}|internal`);
8787
return result;
8888
}
8989

@@ -121,7 +121,7 @@ export class MCPClient {
121121
this.capabilities = result.capabilities;
122122

123123
this.eventEmitter.emit('connected', this.server.name, result);
124-
trackMatomoEvent('ai', 'mcp_connect_success', `${this.server.name}|http`);
124+
trackMatomoEvent('ai', 'remixAI', `mcp_connect_success_${this.server.name}|http`);
125125
return result;
126126
}
127127

@@ -458,7 +458,7 @@ export class MCPClient {
458458
throw new Error(`MCP server ${this.server.name} is not connected`);
459459
}
460460

461-
trackMatomoEvent('ai', 'mcp_resource_read', `${this.server.name}|${uri}`);
461+
trackMatomoEvent('ai', 'remixAI', `mcp_resource_read_${this.server.name}|${uri}`);
462462

463463
if (this.server.transport === 'internal' && this.remixMCPServer) {
464464
const response = await this.remixMCPServer.handleMessage({
@@ -605,7 +605,7 @@ export class MCPClient {
605605
throw new Error(`MCP server ${this.server.name} is not connected`);
606606
}
607607

608-
trackMatomoEvent('ai', 'mcp_tool_call', `${this.server.name}|${toolCall.name}`);
608+
trackMatomoEvent('ai', 'remixAI', `mcp_tool_call_${this.server.name}|${toolCall.name}`);
609609

610610
if (this.server.transport === 'internal' && this.remixMCPServer) {
611611
const response = await this.remixMCPServer.handleMessage({
@@ -615,10 +615,10 @@ export class MCPClient {
615615
});
616616

617617
if (response.error) {
618-
trackMatomoEvent('ai', 'mcp_tool_call_failed', `${this.server.name}|${toolCall.name}|${response.error.message}`);
618+
trackMatomoEvent('ai', 'remixAI', `mcp_tool_call_failed_${this.server.name}|${toolCall.name}|${response.error.message}`);
619619
throw new Error(`Failed to call tool: ${response.error.message}`);
620620
}
621-
trackMatomoEvent('ai', 'mcp_tool_call_success', `${this.server.name}|${toolCall.name}`);
621+
trackMatomoEvent('ai', 'remixAI', `mcp_tool_call_success_${this.server.name}|${toolCall.name}`);
622622
return response.result;
623623
} else if (this.server.transport === 'http') {
624624
const response = await this.sendHTTPRequest({

libs/remix-ai-core/src/inferencers/mcp/mcpInferencer.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { MCPClient } from "./mcpClient";
2121
import { SimpleToolSelector } from "../../services/simpleToolSelector";
2222

2323
// Helper function to track events using MatomoManager instance
24-
function trackMatomoEvent(category: string, action: string, name?: string) {
24+
function trackMatomoEvent(category: string, action: string, name: string) {
2525
try {
2626
if (typeof window !== 'undefined' && (window as any)._matomoManagerInstance) {
2727
const matomoInstance = (window as any)._matomoManagerInstance;
@@ -102,7 +102,6 @@ export class MCPInferencer extends RemoteInferencer implements ICompletions, IGe
102102
}
103103

104104
async connectAllServers(): Promise<void> {
105-
trackMatomoEvent('ai', 'mcp_connect_all_servers', `count:${this.mcpClients.size}`);
106105
const promises = Array.from(this.mcpClients.values()).map(async (client) => {
107106
try {
108107
await client.connect();
@@ -112,8 +111,6 @@ export class MCPInferencer extends RemoteInferencer implements ICompletions, IGe
112111
});
113112

114113
await Promise.allSettled(promises);
115-
const connectedCount = this.getConnectedServers().length;
116-
trackMatomoEvent('ai', 'mcp_connect_all_complete', `connected:${connectedCount}|total:${this.mcpClients.size}`);
117114
}
118115

119116
async disconnectAllServers(): Promise<void> {
@@ -131,7 +128,7 @@ export class MCPInferencer extends RemoteInferencer implements ICompletions, IGe
131128
throw new Error(`MCP server ${server.name} already exists`);
132129
}
133130

134-
trackMatomoEvent('ai', 'mcp_server_add', `${server.name}|${server.transport}`);
131+
trackMatomoEvent('ai', 'remixAI', `mcp_server_add_${server.name}`);
135132

136133
const client = new MCPClient(
137134
server,
@@ -183,7 +180,7 @@ export class MCPInferencer extends RemoteInferencer implements ICompletions, IGe
183180
async removeMCPServer(serverName: string): Promise<void> {
184181
const client = this.mcpClients.get(serverName);
185182
if (client) {
186-
trackMatomoEvent('ai', 'mcp_server_remove', serverName);
183+
trackMatomoEvent('ai', 'remixAI', `mcp_server_remove_${serverName}`);
187184
await client.disconnect();
188185
this.mcpClients.delete(serverName);
189186
this.connectionStatuses.delete(serverName);
@@ -382,7 +379,7 @@ export class MCPInferencer extends RemoteInferencer implements ICompletions, IGe
382379
};
383380

384381
if (llmFormattedTools.length > 0) {
385-
trackMatomoEvent('ai', 'mcp_answer_with_tools', `provider:${options.provider}|tools:${llmFormattedTools.length}`);
382+
trackMatomoEvent('ai', 'remixAI', `mcp_answer_with_tools`);
386383
}
387384

388385
try {
@@ -399,7 +396,6 @@ export class MCPInferencer extends RemoteInferencer implements ICompletions, IGe
399396

400397
toolExecutionCount++;
401398
if (tool_calls && tool_calls.length > 0) {
402-
trackMatomoEvent('ai', 'mcp_llm_tool_execution', `provider:${options.provider}|count:${tool_calls.length}|iteration:${toolExecutionCount}`);
403399
const toolMessages = [];
404400

405401
// Execute all tools and collect results

libs/remix-ai-core/src/remix-mcp-server/RemixMCPServer.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,21 @@ import {
77
IMCPToolResult,
88
IMCPResourceContent
99
} from '../types/mcp';
10+
11+
// Helper function to track events using MatomoManager instance
12+
function trackMatomoEvent(category: string, action: string, name: string) {
13+
try {
14+
if (typeof window !== 'undefined' && (window as any)._matomoManagerInstance) {
15+
const matomoInstance = (window as any)._matomoManagerInstance;
16+
if (typeof matomoInstance.trackEvent === 'function') {
17+
matomoInstance.trackEvent(category, action, name);
18+
}
19+
}
20+
} catch (error) {
21+
// Silent fail for tracking
22+
console.debug('Matomo tracking failed:', error);
23+
}
24+
}
1025
import {
1126
IRemixMCPServer,
1227
RemixMCPServerConfig,
@@ -413,6 +428,7 @@ export class RemixMCPServer extends EventEmitter implements IRemixMCPServer {
413428
execution.endTime = new Date();
414429
this._stats.totalToolCalls++;
415430

431+
trackMatomoEvent('ai', 'remixAI', `mcp_tool_executed_${call.name}`);
416432
console.log(`[RemixMCPServer] Tool '${call.name}' executed successfully`);
417433
this.emit('tool-executed', execution);
418434
return result;
@@ -450,6 +466,10 @@ export class RemixMCPServer extends EventEmitter implements IRemixMCPServer {
450466
// Get from provider
451467
const content = await this._resources.getResourceContent(uri);
452468

469+
// Track resource read
470+
const resourceName = uri.replace('://', '_');
471+
trackMatomoEvent('ai', 'remixAI', `mcp_resource_read_${resourceName}`);
472+
453473
// Cache result
454474
if (this._config.enableResourceCache !== false) {
455475
this._resourceCache.set(uri, {

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

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -57,29 +57,14 @@ export class AdaptiveRateLimiter {
5757
const minIntervalCheck = timeSinceLastRequest < this.minRequestInterval;
5858
const adaptiveCooldownCheck = timeSinceLastCompletion < adaptiveCooldown;
5959

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-
// });
69-
70-
// Check minimum request interval
7160
if (minIntervalCheck) {
72-
// console.log('[AdaptiveRateLimiter] Blocked: minimum request interval not met');
7361
return false;
7462
}
7563

76-
// Check adaptive cooldown
7764
if (adaptiveCooldownCheck) {
78-
// console.log('[AdaptiveRateLimiter] Blocked: adaptive cooldown active');
7965
return false;
8066
}
8167

82-
// console.log('[AdaptiveRateLimiter] Request allowed');
8368
return true;
8469
}
8570

@@ -99,7 +84,6 @@ export class AdaptiveRateLimiter {
9984
timestamp: Date.now(),
10085
accepted: false
10186
});
102-
// console.log('[AdaptiveRateLimiter] Completion shown, total:', this.totalCompletions);
10387
}
10488

10589
trackCompletionAccepted(): void {
@@ -109,13 +93,10 @@ export class AdaptiveRateLimiter {
10993
if (this.recentCompletionHistory.length > 0) {
11094
this.recentCompletionHistory[this.recentCompletionHistory.length - 1].accepted = true;
11195
}
112-
113-
// console.log('[AdaptiveRateLimiter] Completion accepted, total accepted:', this.acceptedCompletions);
11496
}
11597

11698
trackCompletionRejected(): void {
11799
this.rejectedCompletions++;
118-
// console.log('[AdaptiveRateLimiter] Completion rejected, total rejected:', this.rejectedCompletions);
119100
}
120101

121102
private getAdaptiveCooldown(): number {
@@ -149,12 +130,6 @@ export class AdaptiveRateLimiter {
149130
// do not penalize anyone at startup
150131
this.acceptanceRate = 0.5;
151132
}
152-
153-
// console.log('[AdaptiveRateLimiter] Acceptance rate updated:', {
154-
// oldHistoryLength,
155-
// newHistoryLength: this.recentCompletionHistory.length,
156-
// acceptanceRate: this.acceptanceRate
157-
// });
158133
}
159134

160135
getStats(): AdaptiveRateLimiterStats {

0 commit comments

Comments
 (0)