@diologue/local-agent 0.1.2 → 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 +34 -30
- package/dist/cli.mjs.map +2 -2
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -1735,6 +1735,7 @@ var getOnlyActiveBroker = () => {
|
|
|
1735
1735
|
const first = byToken.values().next().value;
|
|
1736
1736
|
return first?.broker ?? null;
|
|
1737
1737
|
};
|
|
1738
|
+
var _activeBrokerCount = () => byToken.size;
|
|
1738
1739
|
|
|
1739
1740
|
// src/routes/llm-shim.ts
|
|
1740
1741
|
var extractBearer = (req) => {
|
|
@@ -1746,26 +1747,35 @@ var extractBearer = (req) => {
|
|
|
1746
1747
|
var sendOpenAIError = (res, status, message, type = "invalid_request_error") => {
|
|
1747
1748
|
res.status(status).json({ error: { message, type } });
|
|
1748
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
|
+
};
|
|
1749
1772
|
var createLlmShimRouter = () => {
|
|
1750
1773
|
const router = createRouter3();
|
|
1751
1774
|
router.post(
|
|
1752
1775
|
"/v1/chat/completions",
|
|
1753
1776
|
async (req, res) => {
|
|
1754
|
-
const
|
|
1755
|
-
if (!
|
|
1756
|
-
sendOpenAIError(res, 401, "Missing Authorization bearer", "auth_error");
|
|
1757
|
-
return;
|
|
1758
|
-
}
|
|
1759
|
-
const broker = getActiveBrokerByToken(token) ?? getOnlyActiveBroker();
|
|
1760
|
-
if (!broker) {
|
|
1761
|
-
sendOpenAIError(
|
|
1762
|
-
res,
|
|
1763
|
-
401,
|
|
1764
|
-
"No active coding-agent stream is currently authorised on this helper.",
|
|
1765
|
-
"auth_error"
|
|
1766
|
-
);
|
|
1767
|
-
return;
|
|
1768
|
-
}
|
|
1777
|
+
const broker = resolveBrokerOr401(req, res);
|
|
1778
|
+
if (!broker) return;
|
|
1769
1779
|
const body = req.body;
|
|
1770
1780
|
if (!body || typeof body !== "object" || !Array.isArray(body.messages) || body.messages.length === 0) {
|
|
1771
1781
|
sendOpenAIError(res, 400, "messages[] is required and must be non-empty");
|
|
@@ -1911,21 +1921,8 @@ var createLlmShimRouter = () => {
|
|
|
1911
1921
|
}
|
|
1912
1922
|
);
|
|
1913
1923
|
router.post("/v1/responses", async (req, res) => {
|
|
1914
|
-
const
|
|
1915
|
-
if (!
|
|
1916
|
-
sendOpenAIError(res, 401, "Missing Authorization bearer", "auth_error");
|
|
1917
|
-
return;
|
|
1918
|
-
}
|
|
1919
|
-
const broker = getActiveBrokerByToken(token);
|
|
1920
|
-
if (!broker) {
|
|
1921
|
-
sendOpenAIError(
|
|
1922
|
-
res,
|
|
1923
|
-
401,
|
|
1924
|
-
"No active coding-agent stream is currently authorised on this helper.",
|
|
1925
|
-
"auth_error"
|
|
1926
|
-
);
|
|
1927
|
-
return;
|
|
1928
|
-
}
|
|
1924
|
+
const broker = resolveBrokerOr401(req, res);
|
|
1925
|
+
if (!broker) return;
|
|
1929
1926
|
const body = req.body;
|
|
1930
1927
|
if (!body || typeof body !== "object" || !Array.isArray(body.input) || body.input.length === 0) {
|
|
1931
1928
|
sendOpenAIError(res, 400, "input[] is required and must be non-empty");
|
|
@@ -2389,6 +2386,13 @@ var OpenCodeProcessAdapter = class {
|
|
|
2389
2386
|
return realCallback(payload);
|
|
2390
2387
|
};
|
|
2391
2388
|
activeBrokerHandle = bindActiveBroker(streamScopedBroker);
|
|
2389
|
+
console.error(
|
|
2390
|
+
`[opencode-adapter] bound active broker token="${activeBrokerHandle.token.slice(0, 12)}\u2026" session=${request.sessionId.slice(0, 8)}`
|
|
2391
|
+
);
|
|
2392
|
+
} else {
|
|
2393
|
+
console.error(
|
|
2394
|
+
`[opencode-adapter] WARNING: request.broker is missing for session=${request.sessionId.slice(0, 8)} \u2014 shim will 401`
|
|
2395
|
+
);
|
|
2392
2396
|
}
|
|
2393
2397
|
const eventController = new AbortController();
|
|
2394
2398
|
const stopOnAbort = () => eventController.abort();
|