LibreChat/api/server/services/Files/provision.js
Danny Avila 34e2ea9319 🏗️ refactor: Move provisioning into the TypeScript workspace
The provisioning service and its ON_TOOL_EXECUTE callback were 600 lines of
implementation under /api, which the workspace rules reserve for thin wrappers,
so none of it was type checked despite its TypeScript callers.

Both now live in packages/api. Storage strategies, vector upload, credential
lookup, and the file model are api-workspace concerns, so they are injected
rather than imported, and what remains on the JS side is 31 lines of wiring. The
service is built on first use for the same reason its axios instance is: this
module is reachable from the OpenAI-compatible controllers, whose suites
partially mock the package, and a load-time call would throw before any
provisioning is requested.

Tests move with the logic and improve in the process: they now exercise the real
service with injected fakes instead of mocking the package that contains it.
2026-08-31 15:20:54 -04:00

23 lines
1.2 KiB
JavaScript

const { createProvisionService } = require('@librechat/api');
const { loadAuthValues } = require('~/server/services/Tools/credentials');
const { uploadVectors } = require('./VectorDB/crud');
const { getStrategyFunctions } = require('./strategies');
/* Wiring only: the provisioning logic lives in packages/api, where it is type checked.
* Storage strategies, vector upload, and credential lookup are api-workspace concerns,
* so they are bound here and injected.
*
* Built on first use rather than at module load: this module is reachable from the
* OpenAI-compatible controllers, whose suites partially mock @librechat/api, and a
* load-time call would throw before any provisioning is requested. */
let service;
const getService = () =>
(service ??= createProvisionService({ getStrategyFunctions, uploadVectors, loadAuthValues }));
module.exports = {
loadCodeApiKey: (...args) => getService().loadCodeApiKey(...args),
provisionToCodeEnv: (...args) => getService().provisionToCodeEnv(...args),
provisionToVectorDB: (...args) => getService().provisionToVectorDB(...args),
checkCodeEnvFileAlive: (...args) => getService().checkCodeEnvFileAlive(...args),
checkSessionsAlive: (...args) => getService().checkSessionsAlive(...args),
};