pendra 0.17.0 → 0.17.1
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 +20 -32
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +20 -32
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -624,8 +624,14 @@ async function parseCompletion(response) {
|
|
|
624
624
|
body
|
|
625
625
|
});
|
|
626
626
|
}
|
|
627
|
+
throwIfInBandError(parsed, "The server reported an error");
|
|
627
628
|
return completionFrom(parsed, body, response.status);
|
|
628
629
|
}
|
|
630
|
+
async function readJsonReply(response) {
|
|
631
|
+
const parsed = await response.json();
|
|
632
|
+
throwIfInBandError(parsed, "The server reported an error");
|
|
633
|
+
return parsed;
|
|
634
|
+
}
|
|
629
635
|
function parseDecryptedCompletion(json, status) {
|
|
630
636
|
let parsed;
|
|
631
637
|
try {
|
|
@@ -1160,7 +1166,7 @@ var Transcriptions = class {
|
|
|
1160
1166
|
const text = await response.text();
|
|
1161
1167
|
return withPlacement({ text }, response.headers);
|
|
1162
1168
|
}
|
|
1163
|
-
const result = await response
|
|
1169
|
+
const result = await readJsonReply(response);
|
|
1164
1170
|
return withPlacement(result, response.headers, result.pendra);
|
|
1165
1171
|
}
|
|
1166
1172
|
/**
|
|
@@ -1561,22 +1567,10 @@ var Completions = class {
|
|
|
1561
1567
|
"/api/v1/chat/completions",
|
|
1562
1568
|
{ method: "POST", body: topLevel, headers }
|
|
1563
1569
|
);
|
|
1564
|
-
const
|
|
1565
|
-
|
|
1566
|
-
try {
|
|
1567
|
-
wrapper = JSON.parse(raw);
|
|
1568
|
-
} catch {
|
|
1569
|
-
throw new APIResponseValidationError("Response was not valid JSON", {
|
|
1570
|
-
status: response.status,
|
|
1571
|
-
body: raw
|
|
1572
|
-
});
|
|
1573
|
-
}
|
|
1574
|
-
if (!wrapper.pendra_encrypted) {
|
|
1575
|
-
throw unsealedReplyError();
|
|
1576
|
-
}
|
|
1577
|
-
const plain = decryptor.openResult(wrapper.pendra_encrypted);
|
|
1570
|
+
const { inner, placement } = await readSealedReply(response);
|
|
1571
|
+
const plain = decryptor.openResult(inner);
|
|
1578
1572
|
const completion = parseDecryptedCompletion(DECODER3.decode(plain), response.status);
|
|
1579
|
-
return withPlacement(completion, response.headers, completion.pendra,
|
|
1573
|
+
return withPlacement(completion, response.headers, completion.pendra, placement);
|
|
1580
1574
|
}
|
|
1581
1575
|
};
|
|
1582
1576
|
|
|
@@ -1645,7 +1639,7 @@ var Embeddings = class {
|
|
|
1645
1639
|
"/api/v1/embeddings",
|
|
1646
1640
|
{ method: "POST", body, headers }
|
|
1647
1641
|
);
|
|
1648
|
-
const result = await response
|
|
1642
|
+
const result = await readJsonReply(response);
|
|
1649
1643
|
return withPlacement(result, response.headers, result.pendra);
|
|
1650
1644
|
}
|
|
1651
1645
|
async createEncrypted(model, body, headers) {
|
|
@@ -1660,13 +1654,10 @@ var Embeddings = class {
|
|
|
1660
1654
|
"/api/v1/embeddings",
|
|
1661
1655
|
{ method: "POST", body: topLevel, headers }
|
|
1662
1656
|
);
|
|
1663
|
-
const
|
|
1664
|
-
|
|
1665
|
-
throw unsealedReplyError();
|
|
1666
|
-
}
|
|
1667
|
-
const plain = decryptor.openResult(wrapper.pendra_encrypted);
|
|
1657
|
+
const { inner, placement } = await readSealedReply(response);
|
|
1658
|
+
const plain = decryptor.openResult(inner);
|
|
1668
1659
|
const result = JSON.parse(DECODER4.decode(plain));
|
|
1669
|
-
return withPlacement(result, response.headers, result.pendra,
|
|
1660
|
+
return withPlacement(result, response.headers, result.pendra, placement);
|
|
1670
1661
|
}
|
|
1671
1662
|
};
|
|
1672
1663
|
|
|
@@ -1709,7 +1700,7 @@ var Generations = class {
|
|
|
1709
1700
|
"/api/v1/images/generations",
|
|
1710
1701
|
{ method: "POST", body, headers }
|
|
1711
1702
|
);
|
|
1712
|
-
const result = await response
|
|
1703
|
+
const result = await readJsonReply(response);
|
|
1713
1704
|
return withPlacement(result, response.headers, result.pendra);
|
|
1714
1705
|
}
|
|
1715
1706
|
async createEncrypted(model, body, headers) {
|
|
@@ -1812,7 +1803,7 @@ var Rerank = class {
|
|
|
1812
1803
|
"/api/v1/rerank",
|
|
1813
1804
|
{ method: "POST", body, headers }
|
|
1814
1805
|
);
|
|
1815
|
-
const result = await response
|
|
1806
|
+
const result = await readJsonReply(response);
|
|
1816
1807
|
return withPlacement(result, response.headers, result.pendra);
|
|
1817
1808
|
}
|
|
1818
1809
|
async createEncrypted(model, body, headers) {
|
|
@@ -1827,18 +1818,15 @@ var Rerank = class {
|
|
|
1827
1818
|
"/api/v1/rerank",
|
|
1828
1819
|
{ method: "POST", body: topLevel, headers }
|
|
1829
1820
|
);
|
|
1830
|
-
const
|
|
1831
|
-
|
|
1832
|
-
throw unsealedReplyError();
|
|
1833
|
-
}
|
|
1834
|
-
const plain = decryptor.openResult(wrapper.pendra_encrypted);
|
|
1821
|
+
const { inner, placement } = await readSealedReply(response);
|
|
1822
|
+
const plain = decryptor.openResult(inner);
|
|
1835
1823
|
const result = JSON.parse(DECODER6.decode(plain));
|
|
1836
|
-
return withPlacement(result, response.headers, result.pendra,
|
|
1824
|
+
return withPlacement(result, response.headers, result.pendra, placement);
|
|
1837
1825
|
}
|
|
1838
1826
|
};
|
|
1839
1827
|
|
|
1840
1828
|
// src/version.ts
|
|
1841
|
-
var VERSION = "0.17.
|
|
1829
|
+
var VERSION = "0.17.1";
|
|
1842
1830
|
var USER_AGENT = `pendra-node/${VERSION}`;
|
|
1843
1831
|
|
|
1844
1832
|
// src/client.ts
|