Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export function createClient(config: CreateClientConfig): Base44Client {
serverUrl,
token,
}),
aiGateway: createAiGatewayModule({ serverUrl, appBaseUrl: normalizedAppBaseUrl, token }),
aiGateway: createAiGatewayModule({ serverUrl, token }),
appLogs: createAppLogsModule(axiosClient, appId),
users: createUsersModule(axiosClient, appId),
analytics: createAnalyticsModule({
Expand Down Expand Up @@ -235,7 +235,7 @@ export function createClient(config: CreateClientConfig): Base44Client {
serverUrl,
token,
}),
aiGateway: createAiGatewayModule({ serverUrl, appBaseUrl: normalizedAppBaseUrl, token: serviceToken }),
aiGateway: createAiGatewayModule({ serverUrl, token: serviceToken }),
appLogs: createAppLogsModule(serviceRoleAxiosClient, appId),
cleanup: () => {
if (socket) {
Expand Down Expand Up @@ -395,7 +395,6 @@ export function createClientFromRequest(request: Request): Base44Client {
);
const appId = request.headers.get("Base44-App-Id");
const serverUrlHeader = request.headers.get("Base44-Api-Url");
const appBaseUrlHeader = request.headers.get("Base44-App-Base-Url");
const functionsVersion = request.headers.get("Base44-Functions-Version");
const stateHeader = request.headers.get("Base44-State");

Expand Down Expand Up @@ -443,7 +442,6 @@ export function createClientFromRequest(request: Request): Base44Client {

return createClient({
serverUrl: serverUrlHeader || "https://base44.app",
appBaseUrl: appBaseUrlHeader ?? undefined,
appId,
token: userToken,
serviceToken: serviceRoleToken,
Expand Down
4 changes: 1 addition & 3 deletions src/modules/ai-gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ import {

export function createAiGatewayModule({
serverUrl,
appBaseUrl,
token,
}: AiGatewayModuleConfig): AiGatewayModule {
const gatewayOrigin = appBaseUrl || serverUrl;
const connection = (): AiGatewayConnection => ({
baseURL: `${gatewayOrigin}/api/ai/openai/v1`,
baseURL: `${serverUrl}/api/ai/openai/v1`,
token: token ?? getAccessToken() ?? "",
});

Expand Down
2 changes: 0 additions & 2 deletions src/modules/ai-gateway.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ export interface AiGatewayConnection {
export interface AiGatewayModuleConfig {
/** Server URL */
serverUrl?: string;
/** The app's own public base URL (e.g. https://my-app.base44.app). */
appBaseUrl?: string;
/** Authentication token */
token?: string;
}
Expand Down
28 changes: 2 additions & 26 deletions tests/unit/ai-gateway.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,45 +25,21 @@ describe("AI Gateway Module", () => {
});
});

test("should prefer appBaseUrl over serverUrl (domain-resolved gateway)", () => {
const base44 = createClient({
serverUrl,
appBaseUrl: "https://my-app.base44.app",
appId,
});
expect(base44.aiGateway.connection().baseURL).toBe(
"https://my-app.base44.app/api/ai/openai/v1"
);
});

test("should build from the Base44-App-Base-Url header in backend functions", () => {
test("should build from the Base44-Api-Url header in backend functions", () => {
const request = new Request("https://functions.internal/run", {
headers: {
"Base44-App-Id": appId,
"Base44-Api-Url": serverUrl,
"Base44-App-Base-Url": "https://my-app.base44.app",
Authorization: "Bearer user-token",
},
});
const base44 = createClientFromRequest(request);
expect(base44.aiGateway.connection()).toEqual({
baseURL: "https://my-app.base44.app/api/ai/openai/v1",
baseURL,
token: "user-token",
});
});

test("should fall back to serverUrl when the app-base-url header is absent", () => {
const request = new Request("https://functions.internal/run", {
headers: {
"Base44-App-Id": appId,
"Base44-Api-Url": serverUrl,
Authorization: "Bearer user-token",
},
});
const base44 = createClientFromRequest(request);
expect(base44.aiGateway.connection().baseURL).toBe(baseURL);
});

test("should use the service-role token via asServiceRole", () => {
const base44 = createClient({
serverUrl,
Expand Down
Loading