Skip to content

Commit 2d2ed99

Browse files
authored
[NA] [FE] fix: assistant sidebar dev mode uses unhashed URLs and single source of truth (#5920)
Dev mode detection is now based on VITE_ASSISTANT_SIDEBAR_BASE_URL instead of import.meta.env.DEV. When set, the manifest fetch is skipped entirely and raw file paths are used through the Vite proxy.
1 parent 61daef9 commit 2d2ed99

3 files changed

Lines changed: 18 additions & 12 deletions

File tree

apps/opik-frontend/src/plugins/comet/AssistantSidebar.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ import useRunnerBridgeSync from "@/hooks/useRunnerBridgeSync";
2727
import { BASE_API_URL } from "@/api/api";
2828
import { Spinner } from "@/ui/spinner";
2929
import AssistantErrorState from "@/plugins/comet/AssistantErrorState";
30+
import {
31+
ASSISTANT_DEV_BASE_URL,
32+
IS_ASSISTANT_DEV,
33+
} from "@/plugins/comet/constants/assistant";
3034

31-
const DEV_BASE_URL = import.meta.env.VITE_ASSISTANT_SIDEBAR_BASE_URL;
32-
const IS_DEV = import.meta.env.DEV;
3335
const BRIDGE_PROTOCOL_VERSION = 1;
3436

3537
const LOADER_DEFAULT_WIDTH = 400;
@@ -219,7 +221,7 @@ const createBridge = (refs: BridgeRefs): AssistantSidebarBridge => ({
219221
);
220222
break;
221223
default:
222-
if (IS_DEV) {
224+
if (IS_ASSISTANT_DEV) {
223225
console.warn(
224226
`[AssistantBridge] Unhandled sidebar event: "${event}"`,
225227
data,
@@ -298,7 +300,7 @@ interface AssistantMeta {
298300
}
299301

300302
function resolveManifestUrl(backendUrl: string | null): string | null {
301-
if (DEV_BASE_URL) return `${DEV_BASE_URL}/manifest.json`;
303+
if (ASSISTANT_DEV_BASE_URL) return `${ASSISTANT_DEV_BASE_URL}/manifest.json`;
302304
if (backendUrl) return `${backendUrl}/console/manifest.json`;
303305
return null;
304306
}
@@ -326,16 +328,16 @@ function useAssistantMeta(backendUrl: string | null): AssistantMeta | null {
326328
return {
327329
scriptUrl: `${manifestBase}/${manifest.js}`,
328330
cssUrl: manifest.css ? `${manifestBase}/${manifest.css}` : undefined,
329-
shellUrl: `${manifestBase}/${manifest.shell}`,
331+
shellUrl: `/assistant/${manifest.shell}`,
330332
version: manifest.ver,
331333
};
332334
},
333-
enabled: !(IS_DEV && DEV_BASE_URL) && !!manifestUrl,
335+
enabled: !IS_ASSISTANT_DEV && !!manifestUrl,
334336
staleTime: Infinity,
335337
retry: 1,
336338
});
337339

338-
if (IS_DEV && DEV_BASE_URL) return DEV_META;
340+
if (IS_ASSISTANT_DEV) return DEV_META;
339341

340342
return data ?? null;
341343
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const ASSISTANT_DEV_BASE_URL =
2+
(import.meta.env.VITE_ASSISTANT_SIDEBAR_BASE_URL as string) ?? "";
3+
4+
export const IS_ASSISTANT_DEV = ASSISTANT_DEV_BASE_URL !== "";

apps/opik-frontend/src/plugins/comet/useAssistantBackend.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { useCallback, useEffect, useRef, useState } from "react";
22
import { useQuery, useQueryClient } from "@tanstack/react-query";
33
import cometApi from "@/plugins/comet/api";
44
import { useActiveWorkspaceName } from "@/store/AppStore";
5+
import { IS_ASSISTANT_DEV } from "@/plugins/comet/constants/assistant";
56

6-
const IS_DEV = import.meta.env.DEV;
77
const HEALTH_POLL_INTERVAL_MS = 5000;
88
const HEALTH_POLL_TIMEOUT_MS = 2 * 60 * 1000; // 2 minutes
99
const HEALTH_KEEPALIVE_MS = 30_000; // 30s keepalive after ready
@@ -92,14 +92,14 @@ export default function useAssistantBackend(
9292
);
9393
return { baseUrl, enabled: true };
9494
},
95-
enabled: !IS_DEV && configEnabled && !!workspaceName,
95+
enabled: !IS_ASSISTANT_DEV && configEnabled && !!workspaceName,
9696
staleTime: Infinity,
9797
retry: 2,
9898
});
9999

100100
const baseUrl = computeResult?.baseUrl ?? null;
101101
const computeEnabled = computeResult?.enabled ?? false;
102-
const shouldPollHealth = !IS_DEV && !!baseUrl && computeEnabled;
102+
const shouldPollHealth = !IS_ASSISTANT_DEV && !!baseUrl && computeEnabled;
103103

104104
// Track when health polling started — only reset when baseUrl changes
105105
// (not on transient shouldPollHealth flickers)
@@ -218,8 +218,8 @@ export default function useAssistantBackend(
218218
queueMicrotask(() => resetBackend());
219219
}
220220

221-
// Dev mode — static URL, no network calls (queries are disabled via enabled: !IS_DEV)
222-
if (IS_DEV) return DEV_RESULT;
221+
// Dev mode or local override — static URL, no network calls
222+
if (IS_ASSISTANT_DEV) return DEV_RESULT;
223223

224224
if (computeResult && !computeResult.enabled)
225225
return notReadyResult(null, "disabled", retry, retryCount);

0 commit comments

Comments
 (0)