refactor(core): convert MULTICA_API_URL constant to getApiBaseUrl() function
Lazy-read process.env at call time instead of module import time. This ensures the env bridge in the Electron main process has time to set process.env.MULTICA_API_URL before the first API request. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
87c03c1368
commit
b8aa5ad7e6
4 changed files with 8 additions and 6 deletions
|
|
@ -5,7 +5,7 @@
|
|||
* All endpoints use GET with query parameters.
|
||||
*/
|
||||
|
||||
import { API_BASE_URL, getAuthHeaders } from "../../../../hub/api-client.js";
|
||||
import { getApiBaseUrl, getAuthHeaders } from "../../../../hub/api-client.js";
|
||||
|
||||
const PATH_PREFIX = "/api/v1/financial";
|
||||
const TIMEOUT_MS = 30_000;
|
||||
|
|
@ -24,7 +24,7 @@ export async function financeFetch<T = Record<string, unknown>>(
|
|||
): Promise<{ data: T; url: string }> {
|
||||
const authHeaders = getAuthHeaders("to use financial data tools");
|
||||
|
||||
const url = new URL(PATH_PREFIX + path, API_BASE_URL);
|
||||
const url = new URL(PATH_PREFIX + path, getApiBaseUrl());
|
||||
for (const [key, value] of Object.entries(params)) {
|
||||
if (value === undefined || value === null) continue;
|
||||
if (Array.isArray(value)) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { Type } from "@sinclair/typebox";
|
||||
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
||||
|
||||
import { API_BASE_URL, getAuthHeaders } from "../../../hub/api-client.js";
|
||||
import { getApiBaseUrl, getAuthHeaders } from "../../../hub/api-client.js";
|
||||
import {
|
||||
DEFAULT_CACHE_TTL_MINUTES,
|
||||
DEFAULT_TIMEOUT_SECONDS,
|
||||
|
|
@ -61,7 +61,7 @@ async function runDevvSearch(params: {
|
|||
}> {
|
||||
const authHeaders = getAuthHeaders("to use web search");
|
||||
|
||||
const res = await fetch(`${API_BASE_URL}${WEB_SEARCH_PATH}`, {
|
||||
const res = await fetch(`${getApiBaseUrl()}${WEB_SEARCH_PATH}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
import { getLocalAuth } from "./auth-store.js";
|
||||
|
||||
export const API_BASE_URL = "https://api.multica.ai";
|
||||
export function getApiBaseUrl(): string {
|
||||
return process.env.MULTICA_API_URL || "https://api.multica.ai";
|
||||
}
|
||||
|
||||
/**
|
||||
* Return auth headers for the proxy API.
|
||||
|
|
|
|||
|
|
@ -2,5 +2,5 @@ export { Hub } from "./hub.js";
|
|||
export type { MessageSource, InboundMessageEvent } from "./hub.js";
|
||||
export { getHubId } from "./hub-identity.js";
|
||||
export { getLocalAuth, type LocalAuthData } from "./auth-store.js";
|
||||
export { API_BASE_URL, getAuthHeaders } from "./api-client.js";
|
||||
export { getApiBaseUrl, getAuthHeaders } from "./api-client.js";
|
||||
export type { HubOptions } from "./types.js";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue