@aliou/pi-neuralwatt 0.16.2 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -33,6 +33,7 @@ function normalizeResolvedConfig(
33
33
  },
34
34
  provider: {
35
35
  api: resolveApi(config.provider?.api),
36
+ apiBaseUrl: resolveApiBaseUrl(config.provider?.apiBaseUrl),
36
37
  },
37
38
  };
38
39
  }
@@ -44,6 +45,30 @@ export function resolveApi(value: string | undefined): NeuralwattApi {
44
45
  return DEFAULT_CONFIG.provider.api;
45
46
  }
46
47
 
48
+ export function resolveApiBaseUrl(value: string | undefined): string {
49
+ const trimmed = value?.trim().replace(/\/+$/u, "");
50
+ if (!trimmed) {
51
+ return DEFAULT_CONFIG.provider.apiBaseUrl;
52
+ }
53
+ try {
54
+ const url = new URL(trimmed);
55
+ if (url.protocol !== "https:" && url.protocol !== "http:") {
56
+ return DEFAULT_CONFIG.provider.apiBaseUrl;
57
+ }
58
+ } catch {
59
+ return DEFAULT_CONFIG.provider.apiBaseUrl;
60
+ }
61
+ return trimmed;
62
+ }
63
+
64
+ export function configuredApiBaseUrl(): string {
65
+ try {
66
+ return configLoader.getConfig().provider.apiBaseUrl;
67
+ } catch {
68
+ return DEFAULT_CONFIG.provider.apiBaseUrl;
69
+ }
70
+ }
71
+
47
72
  export const configLoader = new ConfigLoader<
48
73
  NeuralwattConfig,
49
74
  ResolvedNeuralwattConfig
@@ -23,6 +23,14 @@ export type NeuralwattApi = "openai-completions" | "anthropic-messages";
23
23
  export interface NeuralwattProviderConfig {
24
24
  /** Which API serves model requests. */
25
25
  api?: NeuralwattApi;
26
+
27
+ /**
28
+ * Fallback base URL for Neuralwatt API calls, used only by models that
29
+ * carry no baseUrl of their own (models.json, custom providers, and proxy
30
+ * routing all take precedence) and by the extension's own catalog and
31
+ * quota fetches. Defaults to the direct upstream.
32
+ */
33
+ apiBaseUrl?: string;
26
34
  }
27
35
 
28
36
  export interface NeuralwattConfig {
@@ -54,5 +62,6 @@ export interface ResolvedNeuralwattConfig {
54
62
  };
55
63
  provider: {
56
64
  api: NeuralwattApi;
65
+ apiBaseUrl: string;
57
66
  };
58
67
  }
@@ -1,3 +1,4 @@
1
+ import { configuredApiBaseUrl } from "../config/loader";
1
2
  import type {
2
3
  NeuralwattApiModel,
3
4
  NeuralwattApiModelsResponse,
@@ -5,7 +6,6 @@ import type {
5
6
  import type { NeuralwattQuotas } from "../types/quota-api";
6
7
  import type { QuotasResult } from "../types/quota-result";
7
8
 
8
- const BASE_URL = "https://api.neuralwatt.com/v1";
9
9
  const FETCH_TIMEOUT_MS = 15_000;
10
10
 
11
11
  function authHeaders(apiKey: string | undefined): Record<string, string> {
@@ -31,7 +31,7 @@ async function neuralwattFetch(
31
31
  signal?: AbortSignal,
32
32
  headers?: Record<string, string>,
33
33
  ): Promise<Response> {
34
- return fetch(`${BASE_URL}${path}`, {
34
+ return fetch(`${configuredApiBaseUrl()}${path}`, {
35
35
  headers: { ...authHeaders(apiKey), ...headers },
36
36
  signal: combineSignals(signal),
37
37
  });