@diologue/local-agent 0.1.3 → 0.1.4
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/cli.mjs +26 -34
- package/dist/cli.mjs.map +2 -2
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -1747,30 +1747,35 @@ var extractBearer = (req) => {
|
|
|
1747
1747
|
var sendOpenAIError = (res, status, message, type = "invalid_request_error") => {
|
|
1748
1748
|
res.status(status).json({ error: { message, type } });
|
|
1749
1749
|
};
|
|
1750
|
+
var resolveBrokerOr401 = (req, res) => {
|
|
1751
|
+
const token = extractBearer(req);
|
|
1752
|
+
if (!token) {
|
|
1753
|
+
sendOpenAIError(res, 401, "Missing Authorization bearer", "auth_error");
|
|
1754
|
+
return null;
|
|
1755
|
+
}
|
|
1756
|
+
const broker = getActiveBrokerByToken(token) ?? getOnlyActiveBroker();
|
|
1757
|
+
if (!broker) {
|
|
1758
|
+
const tokenPrefix = token.length > 12 ? `${token.slice(0, 12)}\u2026` : token;
|
|
1759
|
+
console.error(
|
|
1760
|
+
`[llm-shim] 401 on ${req.path}: bearer="${tokenPrefix}" active_brokers=${_activeBrokerCount()}`
|
|
1761
|
+
);
|
|
1762
|
+
sendOpenAIError(
|
|
1763
|
+
res,
|
|
1764
|
+
401,
|
|
1765
|
+
"No active coding-agent stream is currently authorised on this helper.",
|
|
1766
|
+
"auth_error"
|
|
1767
|
+
);
|
|
1768
|
+
return null;
|
|
1769
|
+
}
|
|
1770
|
+
return broker;
|
|
1771
|
+
};
|
|
1750
1772
|
var createLlmShimRouter = () => {
|
|
1751
1773
|
const router = createRouter3();
|
|
1752
1774
|
router.post(
|
|
1753
1775
|
"/v1/chat/completions",
|
|
1754
1776
|
async (req, res) => {
|
|
1755
|
-
const
|
|
1756
|
-
if (!
|
|
1757
|
-
sendOpenAIError(res, 401, "Missing Authorization bearer", "auth_error");
|
|
1758
|
-
return;
|
|
1759
|
-
}
|
|
1760
|
-
const broker = getActiveBrokerByToken(token) ?? getOnlyActiveBroker();
|
|
1761
|
-
if (!broker) {
|
|
1762
|
-
const tokenPrefix = token.length > 12 ? `${token.slice(0, 12)}\u2026` : token;
|
|
1763
|
-
console.error(
|
|
1764
|
-
`[llm-shim] 401 on ${req.path}: bearer="${tokenPrefix}" active_brokers=${_activeBrokerCount()}`
|
|
1765
|
-
);
|
|
1766
|
-
sendOpenAIError(
|
|
1767
|
-
res,
|
|
1768
|
-
401,
|
|
1769
|
-
"No active coding-agent stream is currently authorised on this helper.",
|
|
1770
|
-
"auth_error"
|
|
1771
|
-
);
|
|
1772
|
-
return;
|
|
1773
|
-
}
|
|
1777
|
+
const broker = resolveBrokerOr401(req, res);
|
|
1778
|
+
if (!broker) return;
|
|
1774
1779
|
const body = req.body;
|
|
1775
1780
|
if (!body || typeof body !== "object" || !Array.isArray(body.messages) || body.messages.length === 0) {
|
|
1776
1781
|
sendOpenAIError(res, 400, "messages[] is required and must be non-empty");
|
|
@@ -1916,21 +1921,8 @@ var createLlmShimRouter = () => {
|
|
|
1916
1921
|
}
|
|
1917
1922
|
);
|
|
1918
1923
|
router.post("/v1/responses", async (req, res) => {
|
|
1919
|
-
const
|
|
1920
|
-
if (!
|
|
1921
|
-
sendOpenAIError(res, 401, "Missing Authorization bearer", "auth_error");
|
|
1922
|
-
return;
|
|
1923
|
-
}
|
|
1924
|
-
const broker = getActiveBrokerByToken(token);
|
|
1925
|
-
if (!broker) {
|
|
1926
|
-
sendOpenAIError(
|
|
1927
|
-
res,
|
|
1928
|
-
401,
|
|
1929
|
-
"No active coding-agent stream is currently authorised on this helper.",
|
|
1930
|
-
"auth_error"
|
|
1931
|
-
);
|
|
1932
|
-
return;
|
|
1933
|
-
}
|
|
1924
|
+
const broker = resolveBrokerOr401(req, res);
|
|
1925
|
+
if (!broker) return;
|
|
1934
1926
|
const body = req.body;
|
|
1935
1927
|
if (!body || typeof body !== "object" || !Array.isArray(body.input) || body.input.length === 0) {
|
|
1936
1928
|
sendOpenAIError(res, 400, "input[] is required and must be non-empty");
|