From 2cf896f7bdb12362ed96abeb6451f41f6a396aa3 Mon Sep 17 00:00:00 2001 From: isshaddad Date: Wed, 8 Jul 2026 12:12:12 -0400 Subject: [PATCH] fix(webapp): keep playground chat requests same-origin --- .server-changes/playground-chat-same-origin-base-url.md | 7 +++++++ .../route.tsx | 6 ++++-- 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 .server-changes/playground-chat-same-origin-base-url.md diff --git a/.server-changes/playground-chat-same-origin-base-url.md b/.server-changes/playground-chat-same-origin-base-url.md new file mode 100644 index 0000000000..730f0af468 --- /dev/null +++ b/.server-changes/playground-chat-same-origin-base-url.md @@ -0,0 +1,7 @@ +--- +area: webapp +type: fix +--- + +Fixed the agent playground chat failing to send messages ("Failed to fetch") +in some environments. Messages now reach the agent reliably. diff --git a/apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.playground.$agentParam/route.tsx b/apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.playground.$agentParam/route.tsx index 2c3ac41d7c..581c52c211 100644 --- a/apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.playground.$agentParam/route.tsx +++ b/apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.playground.$agentParam/route.tsx @@ -251,8 +251,10 @@ function PlaygroundChat() { return data.publicAccessToken; }, [actionPath, agent.slug, chatId, tags, machine, maxAttempts, maxDuration, version, region]); - // Resource route prefix — all realtime traffic goes through session-authed routes - const playgroundBaseURL = `${apiOrigin}/resources/orgs/${organization.slug}/projects/${project.slug}/env/${environment.slug}/playground`; + // Same-origin resource routes: use the page origin, not apiOrigin, so in/append + // doesn't go cross-origin (CORS preflight) when API_ORIGIN != APP_ORIGIN. + const origin = typeof window !== "undefined" ? window.location.origin : apiOrigin; + const playgroundBaseURL = `${origin}/resources/orgs/${organization.slug}/projects/${project.slug}/env/${environment.slug}/playground`; // The transport is constructed once (guarded ref below); reading // `startSession` directly there would freeze its closure to the