@burtson-labs/bandit-engine 2.0.40 → 2.0.42
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/README.md +14 -11
- package/dist/{aiProviderStore-JMA5RWX7.mjs → aiProviderStore-UQI33C5E.mjs} +2 -2
- package/dist/{chat-JMWPOSQ4.mjs → chat-XDC4SNJF.mjs} +5 -5
- package/dist/chat-provider.js +156 -106
- package/dist/chat-provider.js.map +1 -1
- package/dist/chat-provider.mjs +4 -4
- package/dist/{chunk-7KEBNVCO.mjs → chunk-4RCAVVDN.mjs} +15 -10
- package/dist/{chunk-7KEBNVCO.mjs.map → chunk-4RCAVVDN.mjs.map} +1 -1
- package/dist/{chunk-QJYPWWA5.mjs → chunk-54ZQ3FSN.mjs} +104 -61
- package/dist/chunk-54ZQ3FSN.mjs.map +1 -0
- package/dist/{chunk-26QQ4CLA.mjs → chunk-EOEI74X4.mjs} +4 -4
- package/dist/{chunk-6ELNWXKC.mjs → chunk-ERV7GLY3.mjs} +4 -4
- package/dist/{chunk-75W5VWPV.mjs → chunk-H4PBQ5LJ.mjs} +51 -46
- package/dist/chunk-H4PBQ5LJ.mjs.map +1 -0
- package/dist/{chunk-D3AGKOM6.mjs → chunk-KBKWVG7X.mjs} +3 -3
- package/dist/{chunk-VIYBZO5W.mjs → chunk-SBNENBUQ.mjs} +3 -3
- package/dist/{chunk-2ZCR2TDY.mjs → chunk-UXE67LR7.mjs} +8 -6
- package/dist/{chunk-2ZCR2TDY.mjs.map → chunk-UXE67LR7.mjs.map} +1 -1
- package/dist/cli.js +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/index.js +164 -109
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +8 -8
- package/dist/management/management.js +164 -109
- package/dist/management/management.js.map +1 -1
- package/dist/management/management.mjs +6 -6
- package/dist/modals/chat-modal/chat-modal.js +108 -63
- package/dist/modals/chat-modal/chat-modal.js.map +1 -1
- package/dist/modals/chat-modal/chat-modal.mjs +4 -4
- package/docs/01_quickstart.md +10 -4
- package/docs/02_gateway_api.md +19 -3
- package/docs/03_provider_integration.md +5 -4
- package/docs/api_reference/media/02_gateway_api.md +19 -3
- package/docs/api_reference/media/README.md +3 -1
- package/package.json +1 -1
- package/dist/chunk-75W5VWPV.mjs.map +0 -1
- package/dist/chunk-QJYPWWA5.mjs.map +0 -1
- /package/dist/{aiProviderStore-JMA5RWX7.mjs.map → aiProviderStore-UQI33C5E.mjs.map} +0 -0
- /package/dist/{chat-JMWPOSQ4.mjs.map → chat-XDC4SNJF.mjs.map} +0 -0
- /package/dist/{chunk-26QQ4CLA.mjs.map → chunk-EOEI74X4.mjs.map} +0 -0
- /package/dist/{chunk-6ELNWXKC.mjs.map → chunk-ERV7GLY3.mjs.map} +0 -0
- /package/dist/{chunk-D3AGKOM6.mjs.map → chunk-KBKWVG7X.mjs.map} +0 -0
- /package/dist/{chunk-VIYBZO5W.mjs.map → chunk-SBNENBUQ.mjs.map} +0 -0
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
management_default
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-4RCAVVDN.mjs";
|
|
4
|
+
import "../chunk-H4PBQ5LJ.mjs";
|
|
5
5
|
import "../chunk-RTQDQ6TC.mjs";
|
|
6
|
-
import "../chunk-
|
|
7
|
-
import "../chunk-
|
|
8
|
-
import "../chunk-
|
|
6
|
+
import "../chunk-ERV7GLY3.mjs";
|
|
7
|
+
import "../chunk-SBNENBUQ.mjs";
|
|
8
|
+
import "../chunk-UXE67LR7.mjs";
|
|
9
9
|
import "../chunk-XUBYA5I7.mjs";
|
|
10
|
-
import "../chunk-
|
|
10
|
+
import "../chunk-54ZQ3FSN.mjs";
|
|
11
11
|
import "../chunk-KCI46M23.mjs";
|
|
12
12
|
import "../chunk-BJTO5JO5.mjs";
|
|
13
13
|
export {
|
|
@@ -1550,61 +1550,15 @@ var init_gateway_service = __esm({
|
|
|
1550
1550
|
*/
|
|
1551
1551
|
chat(request) {
|
|
1552
1552
|
const endpoint = request.provider === "ollama" ? `/api/${request.provider}/chat` : request.provider ? `/api/${request.provider}/chat/completions` : "/api/chat/completions";
|
|
1553
|
-
const
|
|
1553
|
+
const fallbackEndpoint = request.provider === "bandit" ? "/completions" : null;
|
|
1554
1554
|
const normalizedModel = request.provider === "bandit" ? (() => {
|
|
1555
1555
|
const trimmed = (request.model ?? "").replace(/^bandit:/, "").trim();
|
|
1556
1556
|
return trimmed !== "" ? trimmed : "bandit-core-1";
|
|
1557
1557
|
})() : request.model;
|
|
1558
|
-
debugLogger.debug(`Gateway chat request to ${url} with provider: ${request.provider || "default"}`, {
|
|
1559
|
-
model: normalizedModel,
|
|
1560
|
-
messageCount: request.messages.length,
|
|
1561
|
-
hasImages: !!(request.images && request.images.length > 0),
|
|
1562
|
-
imageCount: request.images?.length || 0
|
|
1563
|
-
});
|
|
1564
1558
|
const requestBody = { ...request, model: normalizedModel, stream: request.stream !== false };
|
|
1565
1559
|
return new import_rxjs6.Observable((observer) => {
|
|
1566
1560
|
const controller = new AbortController();
|
|
1567
|
-
const
|
|
1568
|
-
method: "POST",
|
|
1569
|
-
headers: this._getHeaders(),
|
|
1570
|
-
body: JSON.stringify(requestBody),
|
|
1571
|
-
signal: controller.signal
|
|
1572
|
-
});
|
|
1573
|
-
task.then(async (response) => {
|
|
1574
|
-
debugLogger.debug(`Gateway chat response status: ${response.status} for provider: ${request.provider || "default"}`);
|
|
1575
|
-
if (!response.ok) {
|
|
1576
|
-
let errorText = "";
|
|
1577
|
-
let errorData = null;
|
|
1578
|
-
try {
|
|
1579
|
-
errorText = await response.text();
|
|
1580
|
-
debugLogger.error("GatewayService chat error response body", {
|
|
1581
|
-
status: response.status,
|
|
1582
|
-
statusText: response.statusText,
|
|
1583
|
-
url: response.url,
|
|
1584
|
-
body: errorText
|
|
1585
|
-
});
|
|
1586
|
-
} catch (readError) {
|
|
1587
|
-
debugLogger.error("GatewayService chat failed to read error response body", { error: readError });
|
|
1588
|
-
errorText = `Request failed with status ${response.status}`;
|
|
1589
|
-
}
|
|
1590
|
-
try {
|
|
1591
|
-
errorData = JSON.parse(errorText);
|
|
1592
|
-
debugLogger.error("GatewayService chat parsed error payload", errorData);
|
|
1593
|
-
} catch (parseError) {
|
|
1594
|
-
debugLogger.error("GatewayService chat error payload was not valid JSON");
|
|
1595
|
-
errorData = { message: errorText };
|
|
1596
|
-
}
|
|
1597
|
-
const error = this._createHttpError(
|
|
1598
|
-
`POST ${url} failed: ${response.status} ${response.statusText ?? ""}`,
|
|
1599
|
-
{
|
|
1600
|
-
status: response.status,
|
|
1601
|
-
statusText: response.statusText ?? "",
|
|
1602
|
-
data: errorData,
|
|
1603
|
-
url
|
|
1604
|
-
}
|
|
1605
|
-
);
|
|
1606
|
-
throw error;
|
|
1607
|
-
}
|
|
1561
|
+
const handleStreamingResponse = async (response) => {
|
|
1608
1562
|
const reader = response.body?.getReader();
|
|
1609
1563
|
const decoder = new TextDecoder();
|
|
1610
1564
|
let buffer = "";
|
|
@@ -1679,14 +1633,75 @@ var init_gateway_service = __esm({
|
|
|
1679
1633
|
}).catch((err) => observer.error(err));
|
|
1680
1634
|
};
|
|
1681
1635
|
read();
|
|
1682
|
-
}
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1636
|
+
};
|
|
1637
|
+
const sendRequest = (targetEndpoint, allowFallback) => {
|
|
1638
|
+
const url = `${this._baseUrl}${targetEndpoint}`;
|
|
1639
|
+
debugLogger.debug(`Gateway chat request to ${url} with provider: ${request.provider || "default"}`, {
|
|
1640
|
+
model: normalizedModel,
|
|
1641
|
+
messageCount: request.messages.length,
|
|
1642
|
+
hasImages: !!(request.images && request.images.length > 0),
|
|
1643
|
+
imageCount: request.images?.length || 0
|
|
1687
1644
|
});
|
|
1688
|
-
|
|
1689
|
-
|
|
1645
|
+
fetch(url, {
|
|
1646
|
+
method: "POST",
|
|
1647
|
+
headers: this._getHeaders(),
|
|
1648
|
+
body: JSON.stringify(requestBody),
|
|
1649
|
+
signal: controller.signal
|
|
1650
|
+
}).then(async (response) => {
|
|
1651
|
+
debugLogger.debug(`Gateway chat response status: ${response.status} for provider: ${request.provider || "default"}`);
|
|
1652
|
+
if (response.status === 404 && allowFallback && fallbackEndpoint) {
|
|
1653
|
+
debugLogger.warn("GatewayService chat endpoint returned 404, attempting fallback route", {
|
|
1654
|
+
provider: request.provider,
|
|
1655
|
+
attemptedEndpoint: targetEndpoint,
|
|
1656
|
+
fallbackEndpoint
|
|
1657
|
+
});
|
|
1658
|
+
sendRequest(fallbackEndpoint, false);
|
|
1659
|
+
return;
|
|
1660
|
+
}
|
|
1661
|
+
if (!response.ok) {
|
|
1662
|
+
let errorText = "";
|
|
1663
|
+
let errorData = null;
|
|
1664
|
+
try {
|
|
1665
|
+
errorText = await response.text();
|
|
1666
|
+
debugLogger.error("GatewayService chat error response body", {
|
|
1667
|
+
status: response.status,
|
|
1668
|
+
statusText: response.statusText,
|
|
1669
|
+
url: response.url,
|
|
1670
|
+
body: errorText
|
|
1671
|
+
});
|
|
1672
|
+
} catch (readError) {
|
|
1673
|
+
debugLogger.error("GatewayService chat failed to read error response body", { error: readError });
|
|
1674
|
+
errorText = `Request failed with status ${response.status}`;
|
|
1675
|
+
}
|
|
1676
|
+
try {
|
|
1677
|
+
errorData = JSON.parse(errorText);
|
|
1678
|
+
debugLogger.error("GatewayService chat parsed error payload", errorData);
|
|
1679
|
+
} catch (parseError) {
|
|
1680
|
+
debugLogger.error("GatewayService chat error payload was not valid JSON");
|
|
1681
|
+
errorData = { message: errorText };
|
|
1682
|
+
}
|
|
1683
|
+
const error = this._createHttpError(
|
|
1684
|
+
`POST ${url} failed: ${response.status} ${response.statusText ?? ""}`,
|
|
1685
|
+
{
|
|
1686
|
+
status: response.status,
|
|
1687
|
+
statusText: response.statusText ?? "",
|
|
1688
|
+
data: errorData,
|
|
1689
|
+
url
|
|
1690
|
+
}
|
|
1691
|
+
);
|
|
1692
|
+
throw error;
|
|
1693
|
+
}
|
|
1694
|
+
await handleStreamingResponse(response);
|
|
1695
|
+
}).catch((err) => {
|
|
1696
|
+
debugLogger.error("GatewayService chat fetch error", {
|
|
1697
|
+
error: err,
|
|
1698
|
+
url,
|
|
1699
|
+
provider: request.provider
|
|
1700
|
+
});
|
|
1701
|
+
observer.error(err);
|
|
1702
|
+
});
|
|
1703
|
+
};
|
|
1704
|
+
sendRequest(endpoint, true);
|
|
1690
1705
|
return () => {
|
|
1691
1706
|
try {
|
|
1692
1707
|
controller.abort();
|
|
@@ -1819,18 +1834,46 @@ var init_gateway_service = __esm({
|
|
|
1819
1834
|
);
|
|
1820
1835
|
}
|
|
1821
1836
|
_getHeaders() {
|
|
1822
|
-
const
|
|
1837
|
+
const rawToken2 = this._tokenFactory();
|
|
1823
1838
|
const headers = {
|
|
1824
1839
|
"Content-Type": "application/json"
|
|
1825
1840
|
};
|
|
1826
|
-
if (
|
|
1827
|
-
headers["Authorization"] = `Bearer ${token}`;
|
|
1828
|
-
debugLogger.debug("Authorization header set with token");
|
|
1829
|
-
} else {
|
|
1841
|
+
if (!rawToken2) {
|
|
1830
1842
|
debugLogger.warn("GatewayService: No token found, skipping Authorization header");
|
|
1843
|
+
return headers;
|
|
1831
1844
|
}
|
|
1845
|
+
const token = rawToken2.trim();
|
|
1846
|
+
if (token === "") {
|
|
1847
|
+
debugLogger.warn("GatewayService: Token factory returned empty string");
|
|
1848
|
+
return headers;
|
|
1849
|
+
}
|
|
1850
|
+
if (/^(Bearer|ApiKey)\s+/i.test(token)) {
|
|
1851
|
+
headers["Authorization"] = token;
|
|
1852
|
+
debugLogger.debug("GatewayService: Authorization header set with explicit scheme");
|
|
1853
|
+
return headers;
|
|
1854
|
+
}
|
|
1855
|
+
if (this._isLikelyBanditApiKey(token)) {
|
|
1856
|
+
headers["Authorization"] = `ApiKey ${token}`;
|
|
1857
|
+
headers["X-Burtson-Api-Key"] = token;
|
|
1858
|
+
debugLogger.debug("GatewayService: Authorization header set using API key");
|
|
1859
|
+
return headers;
|
|
1860
|
+
}
|
|
1861
|
+
if (this._isLikelyJwt(token)) {
|
|
1862
|
+
headers["Authorization"] = `Bearer ${token}`;
|
|
1863
|
+
debugLogger.debug("GatewayService: Authorization header set using bearer token");
|
|
1864
|
+
return headers;
|
|
1865
|
+
}
|
|
1866
|
+
headers["Authorization"] = `Bearer ${token}`;
|
|
1867
|
+
debugLogger.debug("GatewayService: Authorization header defaulted to bearer scheme");
|
|
1832
1868
|
return headers;
|
|
1833
1869
|
}
|
|
1870
|
+
_isLikelyJwt(token) {
|
|
1871
|
+
const segments = token.split(".");
|
|
1872
|
+
return segments.length === 3 && segments.every((segment) => segment.length > 0);
|
|
1873
|
+
}
|
|
1874
|
+
_isLikelyBanditApiKey(value) {
|
|
1875
|
+
return /^bai_[a-z0-9]{10,}$/i.test(value);
|
|
1876
|
+
}
|
|
1834
1877
|
/**
|
|
1835
1878
|
* Submit feedback to the gateway API
|
|
1836
1879
|
*/
|
|
@@ -8767,9 +8810,11 @@ var useVectorStore = () => {
|
|
|
8767
8810
|
setHasCompatibleProvider(false);
|
|
8768
8811
|
return false;
|
|
8769
8812
|
}
|
|
8770
|
-
const
|
|
8771
|
-
const
|
|
8772
|
-
const
|
|
8813
|
+
const vectorCapableProviders = /* @__PURE__ */ new Set(["ollama", "bandit"]);
|
|
8814
|
+
const isNativeOllama = config.type === "ollama";
|
|
8815
|
+
const hasVectorCapableProvider = typeof config.provider === "string" && vectorCapableProviders.has(config.provider);
|
|
8816
|
+
const isGatewayWithVectorSupport = config.type === "gateway" && hasVectorCapableProvider;
|
|
8817
|
+
const isCompatible = isNativeOllama || isGatewayWithVectorSupport;
|
|
8773
8818
|
setHasCompatibleProvider(isCompatible);
|
|
8774
8819
|
return isCompatible;
|
|
8775
8820
|
} catch (error) {
|