@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.
package/dist/index.js CHANGED
@@ -1624,7 +1624,11 @@ var VertexOpenAIAdapter = class {
1624
1624
  const token = await googleClient.getAccessToken();
1625
1625
  const headers = new Headers(init?.headers);
1626
1626
  headers.set("Authorization", `Bearer ${token.token ?? ""}`);
1627
- return fetch(input, { ...init, headers });
1627
+ const response = await fetch(input, { ...init, headers });
1628
+ if (!response.ok) {
1629
+ return surfaceErrorBody(response, input);
1630
+ }
1631
+ return response;
1628
1632
  };
1629
1633
  this.client = new OpenAI2({
1630
1634
  apiKey: "vertex-ai",
@@ -1670,6 +1674,42 @@ var VertexOpenAIAdapter = class {
1670
1674
  return this.client;
1671
1675
  }
1672
1676
  };
1677
+ async function surfaceErrorBody(response, input) {
1678
+ let body = "";
1679
+ try {
1680
+ body = await response.text();
1681
+ } catch {
1682
+ }
1683
+ const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
1684
+ 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)" : "";
1685
+ if (typeof console !== "undefined" && console.warn) {
1686
+ console.warn(
1687
+ `[vertex-openai] ${response.status} ${response.statusText} from ${url}: ${body || "(empty body)"}${hint}`
1688
+ );
1689
+ }
1690
+ const normalizedBody = unwrapVertexErrorArray(body) + hint;
1691
+ const headers = new Headers(response.headers);
1692
+ headers.delete("content-encoding");
1693
+ headers.delete("content-length");
1694
+ return new Response(normalizedBody, {
1695
+ status: response.status,
1696
+ statusText: response.statusText,
1697
+ headers
1698
+ });
1699
+ }
1700
+ function unwrapVertexErrorArray(body) {
1701
+ if (!body) return body;
1702
+ const trimmed = body.trim();
1703
+ if (!trimmed.startsWith("[")) return body;
1704
+ try {
1705
+ const parsed = JSON.parse(trimmed);
1706
+ if (Array.isArray(parsed) && parsed.length === 1 && parsed[0]?.error) {
1707
+ return JSON.stringify(parsed[0]);
1708
+ }
1709
+ } catch {
1710
+ }
1711
+ return body;
1712
+ }
1673
1713
 
1674
1714
  // src/adapters/vertex-openai/factory.ts
1675
1715
  var vertexOpenAIFactory = {