@antl3x/toolrag
Version:
Context-aware tool retrieval for language models - unlock the full potential of LLM function calling without context window limitations or constraints.
66 lines • 2.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getConfig = exports.setupConfig = void 0;
const zod_1 = require("zod");
const EmbeddingProviderOpenAI_1 = require("./EmbeddingProviderOpenAI");
const EmbeddingProviderGoogle_1 = require("./EmbeddingProviderGoogle");
const ToolRAGConfigSchema = zod_1.z.object({
embeddingProvider: zod_1.z
.union([
zod_1.z.literal('openai'),
zod_1.z.literal('google'),
zod_1.z.instanceof(EmbeddingProviderOpenAI_1.EmbeddingProviderOpenAI),
zod_1.z.instanceof(EmbeddingProviderGoogle_1.EmbeddingProviderGoogle),
])
.default('openai'),
mcpServers: zod_1.z.array(zod_1.z.string()).default([]),
rerank: zod_1.z
.object({
enabled: zod_1.z.boolean().optional(),
threshold: zod_1.z.number().optional(),
})
.optional(),
database: zod_1.z
.object({
url: zod_1.z.string().default('file:./toolreg.db'),
})
.default({}),
});
class ConfigManager {
static instance;
config = null;
constructor() { }
static getInstance() {
if (!ConfigManager.instance) {
ConfigManager.instance = new ConfigManager();
}
return ConfigManager.instance;
}
setup(config) {
try {
this.config = ToolRAGConfigSchema.parse(config);
return this.config;
}
catch (error) {
if (error instanceof zod_1.z.ZodError) {
throw new Error(`Invalid configuration: ${error.message}`);
}
throw error;
}
}
getConfig() {
if (!this.config) {
throw new Error('Configuration not initialized. Call setup() first.');
}
return this.config;
}
}
const setupConfig = (config) => {
return ConfigManager.getInstance().setup(config ?? {});
};
exports.setupConfig = setupConfig;
const getConfig = () => {
return ConfigManager.getInstance().getConfig();
};
exports.getConfig = getConfig;
//# sourceMappingURL=ToolRAGConfig.js.map