АДРЕСНЫЙ РЕЖИМ - локальная подель на декомпозе

This commit is contained in:
2026-04-01 17:55:02 +03:00
parent 4060a5e575
commit 4d59672576
90 changed files with 19595 additions and 785 deletions
+56 -5
View File
@@ -6,23 +6,74 @@ const config_1 = require("../config");
const http_1 = require("../utils/http");
function buildTestConnectionRouter(client) {
const router = (0, express_1.Router)();
router.post("/api/openai/test-connection", async (req, res, next) => {
const handler = async (req, res, next) => {
try {
const body = (req.body ?? {});
const llmProvider = body.llmProvider === "local" ? "local" : "openai";
const model = String(body.model ?? config_1.DEFAULT_MODEL);
const baseUrl = String(body.baseUrl ?? config_1.DEFAULT_OPENAI_BASE_URL);
const apiKey = String(body.apiKey ?? process.env.OPENAI_API_KEY ?? "");
const result = await client.testConnection({
apiKey: String(body.apiKey ?? process.env.OPENAI_API_KEY ?? ""),
model: String(body.model ?? config_1.DEFAULT_MODEL),
baseUrl: String(body.baseUrl ?? config_1.DEFAULT_OPENAI_BASE_URL)
llmProvider,
apiKey,
model,
baseUrl
});
let modelFound = null;
let modelsCount = null;
if (llmProvider === "local") {
try {
const models = await client.listModels({
llmProvider,
apiKey,
model,
baseUrl
});
modelsCount = models.length;
modelFound = models.includes(model);
}
catch {
modelFound = null;
modelsCount = null;
}
}
(0, http_1.ok)(res, {
ok: true,
provider: llmProvider,
model: result.model,
model_found: modelFound,
models_count: modelsCount,
timestamp: new Date().toISOString()
});
}
catch (error) {
next(error);
}
});
};
const listModelsHandler = async (req, res, next) => {
try {
const body = (req.body ?? {});
const models = await client.listModels({
llmProvider: body.llmProvider === "local" ? "local" : "openai",
apiKey: String(body.apiKey ?? process.env.OPENAI_API_KEY ?? ""),
model: String(body.model ?? config_1.DEFAULT_MODEL),
baseUrl: String(body.baseUrl ?? config_1.DEFAULT_OPENAI_BASE_URL)
});
(0, http_1.ok)(res, {
ok: true,
models,
count: models.length,
timestamp: new Date().toISOString()
});
}
catch (error) {
next(error);
}
};
router.post("/api/llm/test-connection", handler);
router.post("/api/llm/models", listModelsHandler);
// Backward-compatible route for old frontend builds.
router.post("/api/openai/test-connection", handler);
router.post("/api/openai/models", listModelsHandler);
return router;
}