@jambonz/llm 0.3.2 → 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.cjs CHANGED
@@ -1731,15 +1731,29 @@ async function surfaceErrorBody(response, input) {
1731
1731
  `[vertex-openai] ${response.status} ${response.statusText} from ${url}: ${body || "(empty body)"}${hint}`
1732
1732
  );
1733
1733
  }
1734
+ const normalizedBody = unwrapVertexErrorArray(body) + hint;
1734
1735
  const headers = new Headers(response.headers);
1735
1736
  headers.delete("content-encoding");
1736
1737
  headers.delete("content-length");
1737
- return new Response(body + hint, {
1738
+ return new Response(normalizedBody, {
1738
1739
  status: response.status,
1739
1740
  statusText: response.statusText,
1740
1741
  headers
1741
1742
  });
1742
1743
  }
1744
+ function unwrapVertexErrorArray(body) {
1745
+ if (!body) return body;
1746
+ const trimmed = body.trim();
1747
+ if (!trimmed.startsWith("[")) return body;
1748
+ try {
1749
+ const parsed = JSON.parse(trimmed);
1750
+ if (Array.isArray(parsed) && parsed.length === 1 && parsed[0]?.error) {
1751
+ return JSON.stringify(parsed[0]);
1752
+ }
1753
+ } catch {
1754
+ }
1755
+ return body;
1756
+ }
1743
1757
 
1744
1758
  // src/adapters/vertex-openai/factory.ts
1745
1759
  var vertexOpenAIFactory = {