Skip to content

Commit f50f437

Browse files
committed
fix(webapp): let the dashboard agent target a different Trigger instance
The agent session-start, token mint, head-start, in-proxy and the client transport all used the webapp's own origin (API_ORIGIN ?? APP_ORIGIN) as the agent instance. That only holds when the agent project runs on the same instance as the webapp. When it doesn't — e.g. a test-cloud webapp using the shared agent project on prod cloud — DASHBOARD_AGENT_SECRET_KEY is a prod-cloud key sent to test-cloud's API, which rejects it ("Invalid API key") and the chat can't start. Add an optional DASHBOARD_AGENT_BASE_URL. dashboardAgentApiOrigin() now returns it, or the SDK default (https://api.trigger.dev) when unset — never the webapp's own origin, and independent of TRIGGER_API_URL (which the webapp may point at an internal host). All server call sites already funnel through that function; the client transport gets the value via the root loader and a useDashboardAgentBaseUrl hook, replacing the general useApiOrigin in the panel. Unset (prod cloud) resolves to the SDK default, matching today's behavior. Test cloud sets DASHBOARD_AGENT_BASE_URL=https://api.trigger.dev.
1 parent ce40d02 commit f50f437

5 files changed

Lines changed: 13 additions & 3 deletions

File tree

apps/webapp/app/components/dashboard-agent/DashboardAgentPanel.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useCallback, useEffect, useMemo, useReducer, useRef, useState } from "r
55
import { AgentSpinner } from "~/components/primitives/Spinner";
66
import { useToast } from "~/components/primitives/Toast";
77
import { useAgentPageContext } from "~/hooks/useAgentPageContext";
8-
import { useApiOrigin } from "~/hooks/useApiOrigin";
8+
import { useDashboardAgentBaseUrl } from "~/hooks/useDashboardAgentBaseUrl";
99
import { useEnvironment } from "~/hooks/useEnvironment";
1010
import { useOrganization } from "~/hooks/useOrganizations";
1111
import { useProject } from "~/hooks/useProject";
@@ -104,7 +104,7 @@ export function DashboardAgentPanel({
104104
const project = useProject();
105105
const environment = useEnvironment();
106106
const user = useUser();
107-
const apiOrigin = useApiOrigin();
107+
const apiOrigin = useDashboardAgentBaseUrl();
108108
const location = useLocation();
109109
const pageContext = useAgentPageContext();
110110
const toast = useToast();

apps/webapp/app/env.server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ const EnvironmentSchema = z
192192
// standard chat.agent SDK flow. When unset, the live agent is disabled — the
193193
// conversation store / History still work, no chat can start.
194194
DASHBOARD_AGENT_SECRET_KEY: z.string().optional(),
195+
DASHBOARD_AGENT_BASE_URL: z.string().optional(),
195196
// Pins agent sessions to a specific deployed version (paired with
196197
// --skip-promotion deploys); unset => the project env's current version.
197198
DASHBOARD_AGENT_VERSION: z.string().optional(),
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { useTypedRouteLoaderData } from "remix-typedjson";
2+
import type { loader } from "../root";
3+
4+
export function useDashboardAgentBaseUrl() {
5+
const routeMatch = useTypedRouteLoaderData<typeof loader>("root");
6+
7+
return routeMatch!.dashboardAgentBaseUrl;
8+
}

apps/webapp/app/root.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
120120
appEnv: env.APP_ENV,
121121
appOrigin: env.APP_ORIGIN,
122122
apiOrigin: env.API_ORIGIN ?? env.APP_ORIGIN,
123+
dashboardAgentBaseUrl: env.DASHBOARD_AGENT_BASE_URL ?? "https://api.trigger.dev",
123124
triggerCliTag: env.TRIGGER_CLI_TAG,
124125
kapa,
125126
timezone,

apps/webapp/app/services/dashboardAgent.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const DASHBOARD_AGENT_UAT_TTL_SECONDS = 10 * 60;
4949
// The Trigger instance this webapp runs against — the same origin the agent
5050
// task calls back to (as the user) for its read tools.
5151
export function dashboardAgentApiOrigin(): string {
52-
return env.API_ORIGIN ?? env.APP_ORIGIN;
52+
return env.DASHBOARD_AGENT_BASE_URL ?? "https://api.trigger.dev";
5353
}
5454

5555
// Mint a short-lived, read-only delegated token for the signed-in user. Self

0 commit comments

Comments
 (0)