Skip to content

Commit 0ab4bea

Browse files
barbinbradsidwebworks
authored andcommitted
refactor: remove logging from direct executor
1 parent ae74fca commit 0ab4bea

1 file changed

Lines changed: 0 additions & 103 deletions

File tree

apps/erp/app/routes/api+/mcp+/lib/direct-executor.ts

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,6 @@ export async function executeFunction(
6161
}
6262
const normalizedArgs = args && typeof args === "object" ? args : undefined;
6363

64-
console.log("[DirectExecutor] Executing function:", functionName);
65-
console.log(
66-
"[DirectExecutor] Args:",
67-
JSON.stringify(normalizedArgs, null, 2)
68-
);
69-
console.log("[DirectExecutor] Context:", {
70-
companyId: context.companyId,
71-
userId: context.userId
72-
});
73-
7464
if (isMcpBlockedTool(functionName)) {
7565
return {
7666
success: false,
@@ -90,17 +80,12 @@ export async function executeFunction(
9080

9181
const moduleName = parts[0];
9282
const funcName = parts.slice(1).join("_");
93-
console.log("[DirectExecutor] Module:", moduleName, "Function:", funcName);
9483

9584
// Get the module functions
9685
const moduleFunctions =
9786
functionRegistry[moduleName as keyof typeof functionRegistry];
9887
if (!moduleFunctions) {
9988
console.error("[DirectExecutor] Module not found:", moduleName);
100-
console.log(
101-
"[DirectExecutor] Available modules:",
102-
Object.keys(functionRegistry)
103-
);
10489
throw new Error(`Module not found: ${moduleName}`);
10590
}
10691

@@ -113,13 +98,8 @@ export async function executeFunction(
11398
"in module",
11499
moduleName
115100
);
116-
console.log(
117-
"[DirectExecutor] Available functions in module:",
118-
Object.keys(moduleFunctions)
119-
);
120101
throw new Error(`Function not found: ${funcName} in module ${moduleName}`);
121102
}
122-
console.log("[DirectExecutor] Function found successfully");
123103

124104
try {
125105
// Get function parameter names by converting to string and parsing
@@ -131,41 +111,25 @@ export async function executeFunction(
131111
?.map((p: string) => p.trim().split(/[=\s]/)[0])
132112
?.filter((p: string) => p) || [];
133113

134-
console.log("[DirectExecutor] Function parameters:", paramNames);
135-
136114
// Build arguments array based on parameter names
137115
const functionArgs: any[] = [];
138116

139117
for (const paramName of paramNames) {
140118
if (paramName === "client") {
141119
functionArgs.push(context.client);
142-
console.log("[DirectExecutor] Added client to args");
143120
} else if (paramName === "userId") {
144121
const userIdValue = normalizedArgs?.userId || context.userId;
145122
functionArgs.push(userIdValue);
146-
console.log("[DirectExecutor] Added userId to args:", userIdValue);
147123
} else if (paramName === "companyId") {
148124
const companyIdValue = normalizedArgs?.companyId || context.companyId;
149125
functionArgs.push(companyIdValue);
150-
console.log(
151-
"[DirectExecutor] Added companyId to args:",
152-
companyIdValue
153-
);
154126
} else if (paramName === "args") {
155127
// For 'args' parameter, pass the entire args object or a default
156128
// This is the parameter that most service functions expect
157129
const argsValue = normalizedArgs || {};
158130
functionArgs.push(argsValue);
159-
console.log(
160-
"[DirectExecutor] Added args object:",
161-
JSON.stringify(argsValue, null, 2)
162-
);
163131
} else if (normalizedArgs && paramName in normalizedArgs) {
164132
functionArgs.push(normalizedArgs[paramName]);
165-
console.log(
166-
`[DirectExecutor] Added ${paramName} from args:`,
167-
normalizedArgs[paramName]
168-
);
169133
} else if (
170134
normalizedArgs &&
171135
Object.keys(normalizedArgs).length === 1 &&
@@ -174,98 +138,31 @@ export async function executeFunction(
174138
// If single arg that doesn't match param names, use it as positional
175139
const value = Object.values(normalizedArgs)[0];
176140
functionArgs.push(value);
177-
console.log("[DirectExecutor] Added single positional arg:", value);
178141
} else {
179142
// Skip optional parameters
180-
console.log(
181-
`[DirectExecutor] Skipping optional parameter: ${paramName}`
182-
);
183143
continue;
184144
}
185145
}
186146

187-
console.log(
188-
"[DirectExecutor] Calling function with args:",
189-
functionArgs.length,
190-
"arguments"
191-
);
192-
// Don't log the client object as it causes circular reference
193-
const loggableArgs = functionArgs.map((arg, i) => {
194-
if (paramNames[i] === "client") return "[SupabaseClient]";
195-
return arg;
196-
});
197-
console.log(
198-
"[DirectExecutor] Actual args being passed:",
199-
JSON.stringify(loggableArgs, null, 2)
200-
);
201-
202147
// Execute the function
203148
let result = await (func as Function)(...functionArgs);
204149

205-
console.log("[DirectExecutor] Function executed successfully");
206-
console.log("[DirectExecutor] Raw result type:", typeof result);
207-
208150
// Check if result is a Supabase query builder (it's thenable but not yet executed)
209151
// Supabase queries are thenable objects that need to be awaited
210152
if (
211153
result &&
212154
typeof result === "object" &&
213155
typeof result.then === "function"
214156
) {
215-
console.log(
216-
"[DirectExecutor] Result is thenable (likely Supabase query), awaiting execution..."
217-
);
218157
try {
219158
const executedResult = await result;
220-
console.log("[DirectExecutor] Query executed successfully");
221-
console.log(
222-
"[DirectExecutor] Executed result type:",
223-
typeof executedResult
224-
);
225-
if (executedResult && typeof executedResult === "object") {
226-
console.log(
227-
"[DirectExecutor] Result has keys:",
228-
Object.keys(executedResult)
229-
);
230-
if ("data" in executedResult) {
231-
console.log(
232-
"[DirectExecutor] Result has data property, length:",
233-
Array.isArray(executedResult.data)
234-
? executedResult.data.length
235-
: "not array"
236-
);
237-
}
238-
if ("error" in executedResult) {
239-
console.log(
240-
"[DirectExecutor] Result has error:",
241-
executedResult.error
242-
);
243-
}
244-
if ("count" in executedResult) {
245-
console.log("[DirectExecutor] Result count:", executedResult.count);
246-
}
247-
}
248159
result = executedResult;
249160
} catch (queryError: any) {
250161
console.error("[DirectExecutor] Query execution failed:", queryError);
251162
throw queryError;
252163
}
253164
}
254165

255-
// Log result safely
256-
try {
257-
const resultPreview = JSON.stringify(result, null, 2).substring(0, 500);
258-
console.log("[DirectExecutor] Final result preview:", resultPreview);
259-
} catch (_e) {
260-
console.log(
261-
"[DirectExecutor] Could not stringify result, likely contains circular references"
262-
);
263-
console.log(
264-
"[DirectExecutor] Result keys:",
265-
result && typeof result === "object" ? Object.keys(result) : "N/A"
266-
);
267-
}
268-
269166
return {
270167
success: true,
271168
data: result

0 commit comments

Comments
 (0)