Skip to content

Commit 88ee5fc

Browse files
committed
fix(app-shell): keep aiApiBase.ts, which the sidebar now reads
Main's UnifiedSidebar (#38005) imports resolveAiApiBase from hooks/aiApiBase.js, the module this PR had folded back into useAiSurface.ts. The module stays, for the reason it was split out: a reader that needs only the URL must not import the surface hook's module, which the layout tests mock without resolveAiApiBase. useAiSurface.ts imports and re-exports it as main does; only the module's doc comment changes (its first reader, useAskAiHandler, leaves with ask_ai). Claude-Session: https://claude.ai/code/session_01L9qibzCKZkVMWDVKhZVdRK Co-authored-by: Claude <noreply@anthropic.com>
1 parent 3268c3e commit 88ee5fc

2 files changed

Lines changed: 24 additions & 12 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* The AI service base URL, in a module of its own so a reader that only needs
5+
* the URL (the sidebar's conversation favourites, `UnifiedSidebar`) does not
6+
* import the surface hook's module, which many layout tests replace with a
7+
* mock that carries no `resolveAiApiBase`.
8+
*/
9+
10+
/**
11+
* Resolve the AI service base URL, mirroring AiChatPage / the Home CTAs:
12+
* an explicit `VITE_AI_BASE_URL` wins, otherwise `${VITE_SERVER_URL}/api/v1/ai`.
13+
* Shared so every catalog fetch (route guard, layouts, Home) hits the same URL.
14+
*/
15+
export function resolveAiApiBase(): string {
16+
const env = (import.meta as any).env ?? {};
17+
const fromEnv = env.VITE_AI_BASE_URL as string | undefined;
18+
if (fromEnv) return fromEnv.replace(/\/$/, '');
19+
const serverUrl = (env.VITE_SERVER_URL as string | undefined) ?? '';
20+
return `${serverUrl.replace(/\/$/, '')}/api/v1/ai`;
21+
}

‎ui/packages/app-shell/src/hooks/useAiSurface.ts‎

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,10 @@
4242

4343
import { useAgents } from '@object-ui/plugin-chatbot/core';
4444
import { catalogServesBuild } from './surfaceAgent.js';
45+
import { resolveAiApiBase } from './aiApiBase.js';
4546

46-
/**
47-
* Resolve the AI service base URL, mirroring AiChatPage / the Home CTAs:
48-
* an explicit `VITE_AI_BASE_URL` wins, otherwise `${VITE_SERVER_URL}/api/v1/ai`.
49-
* Shared so every catalog fetch (route guard, layouts, Home) hits the same URL.
50-
*/
51-
export function resolveAiApiBase(): string {
52-
const env = (import.meta as any).env ?? {};
53-
const fromEnv = env.VITE_AI_BASE_URL as string | undefined;
54-
if (fromEnv) return fromEnv.replace(/\/$/, '');
55-
const serverUrl = (env.VITE_SERVER_URL as string | undefined) ?? '';
56-
return `${serverUrl.replace(/\/$/, '')}/api/v1/ai`;
57-
}
47+
// Re-exported where its callers have always imported it from.
48+
export { resolveAiApiBase };
5849

5950
export interface AiSurfaceState {
6051
/** True when the AI UI should render — the CALLER can reach >= 1 agent (access-filtered). */

0 commit comments

Comments
 (0)