@jambonz/llm 0.3.1 → 0.3.3

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.
@@ -1617,7 +1617,11 @@ var VertexOpenAIAdapter = class {
1617
1617
  const token = await googleClient.getAccessToken();
1618
1618
  const headers = new Headers(init2?.headers);
1619
1619
  headers.set("Authorization", `Bearer ${token.token ?? ""}`);
1620
- return fetch(input, { ...init2, headers });
1620
+ const response = await fetch(input, { ...init2, headers });
1621
+ if (!response.ok) {
1622
+ return surfaceErrorBody(response, input);
1623
+ }
1624
+ return response;
1621
1625
  };
1622
1626
  this.client = new OpenAI2({
1623
1627
  apiKey: "vertex-ai",
@@ -1663,6 +1667,42 @@ var VertexOpenAIAdapter = class {
1663
1667
  return this.client;
1664
1668
  }
1665
1669
  };
1670
+ async function surfaceErrorBody(response, input) {
1671
+ let body = "";
1672
+ try {
1673
+ body = await response.text();
1674
+ } catch {
1675
+ }
1676
+ const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
1677
+ const hint = response.status === 404 && !body ? " (no body returned \u2014 most commonly means the requested model is not hosted in this region; check Google's partner-model availability matrix)" : "";
1678
+ if (typeof console !== "undefined" && console.warn) {
1679
+ console.warn(
1680
+ `[vertex-openai] ${response.status} ${response.statusText} from ${url}: ${body || "(empty body)"}${hint}`
1681
+ );
1682
+ }
1683
+ const normalizedBody = unwrapVertexErrorArray(body) + hint;
1684
+ const headers = new Headers(response.headers);
1685
+ headers.delete("content-encoding");
1686
+ headers.delete("content-length");
1687
+ return new Response(normalizedBody, {
1688
+ status: response.status,
1689
+ statusText: response.statusText,
1690
+ headers
1691
+ });
1692
+ }
1693
+ function unwrapVertexErrorArray(body) {
1694
+ if (!body) return body;
1695
+ const trimmed = body.trim();
1696
+ if (!trimmed.startsWith("[")) return body;
1697
+ try {
1698
+ const parsed = JSON.parse(trimmed);
1699
+ if (Array.isArray(parsed) && parsed.length === 1 && parsed[0]?.error) {
1700
+ return JSON.stringify(parsed[0]);
1701
+ }
1702
+ } catch {
1703
+ }
1704
+ return body;
1705
+ }
1666
1706
 
1667
1707
  // src/adapters/vertex-openai/factory.ts
1668
1708
  var vertexOpenAIFactory = {