@broberg/ai-sdk 0.36.4 → 0.36.6

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.
package/dist/index.d.ts CHANGED
@@ -17,14 +17,25 @@ export { AvailabilitySource, AvailabilityStatus, ModelStatus, ModelUnavailableEr
17
17
  type Region = "eu" | "us" | "cn" | "unknown";
18
18
  /** Region of the endpoint a call will actually hit. Never throws — a residency
19
19
  * reading must not be able to break a call that already succeeded. */
20
- declare function regionOfHost(url: string | undefined): Region;
20
+ declare function regionOfHost(hostOrUrl: string | undefined): Region;
21
21
  /** Classify a provider REGION STRING — a Vertex/GCP location like `europe-west1`, or
22
22
  * an Azure region like `westeurope`. Anything unrecognised is `"unknown"`: a region
23
23
  * name we have never seen is exactly the case where guessing is most tempting and
24
24
  * least defensible. Never throws — a residency reading must not be able to break a
25
25
  * call that already succeeded. */
26
26
  declare function classifyRegionName(name: string | undefined): Region;
27
- /** Region for an adapter whose endpoint is fixed. Unknown provider → `"unknown"`. */
27
+ /** Region for an adapter whose endpoint is fixed. Unknown provider → `"unknown"`.
28
+ *
29
+ * **DO NOT BUILD A RESIDENCY GUARD ON THIS.** Use {@link regionOfHost} on the base URL
30
+ * the call will actually use. Found by a consumer building exactly that guard (super,
31
+ * 2026-08-30): `regionOfProvider("mistral")` is `"unknown"` — correct, because Mistral
32
+ * takes a `baseUrl` and a name cannot answer for residency — but a guard written as
33
+ * `regionOfProvider(p) === "eu"` therefore REJECTS Mistral, which is the only EU route
34
+ * we have. It fails closed and is useless: it filters out the thing it exists to allow.
35
+ *
36
+ * The trap is invisible from the signature, which is why it is written here rather than
37
+ * only in the docs. This function answers "is this provider's endpoint fixed, and where
38
+ * is it?" — a narrower question than "where will my call go?". */
28
39
  declare function regionOfProvider(provider: string): Region;
29
40
 
30
41
  /** How a call reaches the model. `http` = provider REST API; `subprocess` = local
@@ -2189,8 +2200,8 @@ declare const falStubAdapter: ProviderAdapter;
2189
2200
  * wires the live adapters. */
2190
2201
  declare const stubProviders: Record<string, ProviderAdapter>;
2191
2202
 
2192
- declare const VERSION: "0.36.4";
2193
- declare const SDK_TAG: "@broberg/ai-sdk@0.36.4";
2203
+ declare const VERSION: "0.36.6";
2204
+ declare const SDK_TAG: "@broberg/ai-sdk@0.36.6";
2194
2205
 
2195
2206
  /** Built-in defaults. Every entry is overridable via AiConfig.defaults or a
2196
2207
  * per-call override.
package/dist/index.js CHANGED
@@ -241,14 +241,20 @@ var HOST_REGION = {
241
241
  "openrouter.ai": "unknown",
242
242
  "router.requesty.ai": "unknown"
243
243
  };
244
- function regionOfHost(url) {
245
- if (!url) return "unknown";
244
+ function regionOfHost(hostOrUrl) {
245
+ if (!hostOrUrl) return "unknown";
246
+ const trimmed = hostOrUrl.trim();
247
+ if (!trimmed) return "unknown";
248
+ let host = "";
246
249
  try {
247
- const host = new URL(url).host.toLowerCase();
248
- return Object.hasOwn(HOST_REGION, host) ? HOST_REGION[host] : "unknown";
250
+ host = new URL(trimmed).host;
249
251
  } catch {
250
- return "unknown";
251
252
  }
253
+ if (!host) {
254
+ host = trimmed.split("/")[0].split("@").pop().split(":")[0];
255
+ }
256
+ host = host.toLowerCase();
257
+ return Object.hasOwn(HOST_REGION, host) ? HOST_REGION[host] : "unknown";
252
258
  }
253
259
  var FIXED_PROVIDER_REGION = {
254
260
  // NB: mistral and deepl are deliberately ABSENT — both take a config.baseUrl, so
@@ -303,6 +309,7 @@ function classifyRegionName(name) {
303
309
  if (!name) return "unknown";
304
310
  const n = name.trim().toLowerCase();
305
311
  if (!n) return "unknown";
312
+ if (n === "eu" || n === "us" || n === "cn" || n === "unknown") return n;
306
313
  if (n.startsWith("europe-")) return "eu";
307
314
  if (n.startsWith("us-")) return "us";
308
315
  if (EU_REGION_NAMES.has(n)) return "eu";
@@ -2986,8 +2993,8 @@ var aiConfigSchema = z.object({
2986
2993
  });
2987
2994
 
2988
2995
  // src/version.ts
2989
- var VERSION = "0.36.4";
2990
- var SDK_TAG = "@broberg/ai-sdk@0.36.4";
2996
+ var VERSION = "0.36.6";
2997
+ var SDK_TAG = "@broberg/ai-sdk@0.36.6";
2991
2998
 
2992
2999
  // src/cost/sinks/upmetrics.ts
2993
3000
  function upmetricsSink(config) {