Skip to content

Commit eba1bd8

Browse files
committed
fix: normalize local internal fetch URLs from HTTPS to HTTP to avoid TLS ERR_SSL_PACKET_LENGTH_TOO_LONG
1 parent 484b3e2 commit eba1bd8

3 files changed

Lines changed: 21 additions & 4 deletions

File tree

app/api/webhooks/github/route.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,10 @@ export async function POST(request: Request) {
407407

408408
// Trigger initial deployments - await to ensure it completes
409409
try {
410-
const origin = new URL(request.url).origin;
410+
let origin = new URL(request.url).origin;
411+
if (/^https:\/\/(localhost|127\.0\.0\.1|\[::1\])/i.test(origin)) {
412+
origin = origin.replace(/^https:/i, "http:");
413+
}
411414
console.log(`[Initial Deploy] Triggering for ${repoFullName} at ${origin}/api/deployments/initial`);
412415

413416
const initialDeployResponse = await fetch(`${origin}/api/deployments/initial`, {

lib/ai/chat-actions.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,11 @@ function getInternalApiBaseUrl(): string {
609609
if (candidate?.trim()) {
610610
const url = candidate.trim();
611611
// Ensure URL has protocol
612-
const withProtocol = /^https?:\/\//i.test(url) ? url : `https://${url}`;
612+
let withProtocol = /^https?:\/\//i.test(url) ? url : `https://${url}`;
613+
// Normalize local URLs to use HTTP instead of HTTPS to avoid local SSL handshake errors
614+
if (/^https:\/\/(localhost|127\.0\.0\.1|\[::1\])/i.test(withProtocol)) {
615+
withProtocol = withProtocol.replace(/^https:/i, "http:");
616+
}
613617
return withProtocol.replace(/\/$/, "");
614618
}
615619
}

lib/ai/foundry-kb.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ export async function callWithFoundryKnowledgeBase(
2121
`${projectEndpoint}/openai/deployments/${deployment}/chat/completions` +
2222
`?api-version=2025-01-01-preview`;
2323

24+
console.log(`[foundry-kb] calling → ${url}`);
25+
console.log(`[foundry-kb] knowledge base: ${knowledgeBase} | search endpoint: ${openAiEndpoint}`);
26+
2427
try {
2528
const res = await fetch(url, {
2629
method: "POST",
@@ -51,14 +54,21 @@ export async function callWithFoundryKnowledgeBase(
5154

5255
if (!res.ok) {
5356
const errBody = await res.text().catch(() => "");
54-
console.warn("[foundry-kb] data_sources call failed:", res.status, errBody);
57+
console.warn("[foundry-kb] failed:", res.status, errBody);
5558
return null;
5659
}
5760

5861
const json = await res.json();
62+
const citations = json.choices?.[0]?.message?.context?.citations ?? [];
63+
console.log(`[foundry-kb] ✅ grounded — ${citations.length} citation(s) from knowledge base`);
64+
if (citations.length > 0) {
65+
citations.forEach((c: any, i: number) => {
66+
console.log(` [${i + 1}] ${c.title ?? c.filepath ?? "untitled"}`);
67+
});
68+
}
5969
return (json.choices?.[0]?.message?.content as string) ?? null;
6070
} catch (err) {
61-
console.warn("[foundry-kb] data_sources call error:", err);
71+
console.warn("[foundry-kb] error:", err);
6272
return null;
6373
}
6474
}

0 commit comments

Comments
 (0)