Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions shared/mesh-chat/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,37 +73,10 @@ export async function callDecopilotAPI(
toolApprovalLevel: "yolo" as const,
};

console.log(`[MeshChat] ========== callDecopilotAPI ==========`);
console.log(`[MeshChat] URL: ${url}`);
console.log(
`[MeshChat] Model: ${modelId}, Provider: ${resolveProvider(modelId)}, Connection: ${modelProviderId ?? "none"}`,
);
console.log(`[MeshChat] Agent: id=${agentId ?? "none"}, mode=${agentMode}`);
console.log(
`[MeshChat] Messages: ${messages.length}, timeout: ${timeoutMs}ms`,
);
console.log(
`[MeshChat] Effective mesh URL: ${effectiveMeshUrl} (original: ${meshUrl})`,
);
messages.forEach((m, i) => {
const partsDesc = m.parts
.map((p) =>
p.type === "text"
? `text(${(p as any).text?.length ?? 0})`
: `file(${(p as any).filename ?? "?"})`,
)
.join(", ");
console.log(
`[MeshChat] Message[${i}]: role=${m.role}, parts=[${partsDesc}]`,
);
});

const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), timeoutMs);

const fetchStartTime = Date.now();
try {
console.log(`[MeshChat] Sending request to Decopilot API...`);
const response = await fetch(url, {
method: "POST",
headers: {
Expand All @@ -115,18 +88,8 @@ export async function callDecopilotAPI(
signal: controller.signal,
});

console.log(
`[MeshChat] Decopilot API response: status=${response.status}, ok=${response.ok}, time=${Date.now() - fetchStartTime}ms`,
);
console.log(
`[MeshChat] Response headers: content-type=${response.headers.get("content-type")}`,
);

if (!response.ok) {
const errorText = await response.text();
console.error(
`[MeshChat] Decopilot API FAILED: status=${response.status}, body length=${errorText.length}`,
);
throw new Error(
`Decopilot API call failed (${response.status}): ${errorText}`,
);
Expand Down
28 changes: 3 additions & 25 deletions shared/mesh-chat/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,31 +106,22 @@ export async function generateResponse(
): Promise<string> {
const apiMessages = messagesToPrompt(messages, config.systemPrompt);

console.log(
"[MeshChat] ========== generateResponse (non-streaming) ==========",
);
console.log("[MeshChat] Generating response", {
messageCount: apiMessages.length,
modelId: config.modelId,
hasAgent: !!config.agentId,
agentId: config.agentId,
meshUrl: config.meshUrl,
});

const startTime = Date.now();
const response = await callDecopilotAPI(config, apiMessages);

if (!response.body) {
console.error("[MeshChat] No response body from Decopilot API!");
throw new Error("No response body from Decopilot API");
}

console.log(`[MeshChat] Collecting stream text...`);
const text = await collectFullStreamText(response.body);

console.log(
`[MeshChat] Response fully collected in ${Date.now() - startTime}ms (${text.length} chars)`,
);
console.log(`[MeshChat] Response received (${text.length} chars)`);

return text || "Desculpe, não consegui gerar uma resposta.";
}

Expand All @@ -148,30 +139,17 @@ export async function generateResponseWithStreaming(
): Promise<string> {
const apiMessages = messagesToPrompt(messages, config.systemPrompt);

console.log("[MeshChat] ========== generateResponseWithStreaming ==========");
console.log("[MeshChat] Generating response (streaming)", {
messageCount: apiMessages.length,
modelId: config.modelId,
hasAgent: !!config.agentId,
agentId: config.agentId,
meshUrl: config.meshUrl,
});

const startTime = Date.now();
const response = await callDecopilotAPI(config, apiMessages);

if (!response.body) {
console.error(
"[MeshChat] No response body from Decopilot API (streaming)!",
);
throw new Error("No response body from Decopilot API");
}

console.log(`[MeshChat] Starting stream processing...`);
const result = await processStreamWithCallback(response.body, onStream);
console.log(
`[MeshChat] Streaming completed in ${Date.now() - startTime}ms (${result.length} chars)`,
);

return result;
return processStreamWithCallback(response.body, onStream);
}
Loading