diff --git a/apps/app/src/lib/__tests__/agent-url-regression.test.ts b/apps/app/src/lib/__tests__/agent-url-regression.test.ts new file mode 100644 index 0000000..d5a59f4 --- /dev/null +++ b/apps/app/src/lib/__tests__/agent-url-regression.test.ts @@ -0,0 +1,3 @@ +import { it, expect } from "vitest"; +import { normalizeLanggraphUrl } from "../copilotkit-runtime-options"; +it.each([[" ","http://localhost:8123"],[" https://agent.example.com/ ","https://agent.example.com/"],[" agent:8123 ","http://agent:8123"],["HTTPS://agent.example.com","HTTPS://agent.example.com"]])("normalizes deployment URL %s", (raw,expected) => expect(normalizeLanggraphUrl(raw)).toBe(expected)); diff --git a/apps/app/src/lib/copilotkit-runtime-options.ts b/apps/app/src/lib/copilotkit-runtime-options.ts index 0e34681..73515b8 100644 --- a/apps/app/src/lib/copilotkit-runtime-options.ts +++ b/apps/app/src/lib/copilotkit-runtime-options.ts @@ -17,8 +17,9 @@ export interface RuntimeOptionsEnv { // Normalize Render's fromService hostport (bare host:port) into a full URL export function normalizeLanggraphUrl(raw?: string): string { - if (!raw) return "http://localhost:8123"; - return raw.startsWith("http") ? raw : `http://${raw}`; + const value = raw?.trim(); + if (!value) return "http://localhost:8123"; + return /^https?:\/\//i.test(value) ? value : `http://${value}`; } export function buildRuntimeOptions(env: RuntimeOptionsEnv) {