Skip to content

Commit 2cf896f

Browse files
committed
fix(webapp): keep playground chat requests same-origin
1 parent 6e827f1 commit 2cf896f

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
area: webapp
3+
type: fix
4+
---
5+
6+
Fixed the agent playground chat failing to send messages ("Failed to fetch")
7+
in some environments. Messages now reach the agent reliably.

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.playground.$agentParam/route.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,10 @@ function PlaygroundChat() {
251251
return data.publicAccessToken;
252252
}, [actionPath, agent.slug, chatId, tags, machine, maxAttempts, maxDuration, version, region]);
253253

254-
// Resource route prefix — all realtime traffic goes through session-authed routes
255-
const playgroundBaseURL = `${apiOrigin}/resources/orgs/${organization.slug}/projects/${project.slug}/env/${environment.slug}/playground`;
254+
// Same-origin resource routes: use the page origin, not apiOrigin, so in/append
255+
// doesn't go cross-origin (CORS preflight) when API_ORIGIN != APP_ORIGIN.
256+
const origin = typeof window !== "undefined" ? window.location.origin : apiOrigin;
257+
const playgroundBaseURL = `${origin}/resources/orgs/${organization.slug}/projects/${project.slug}/env/${environment.slug}/playground`;
256258

257259
// The transport is constructed once (guarded ref below); reading
258260
// `startSession` directly there would freeze its closure to the

0 commit comments

Comments
 (0)