@sirmrmarty/n8n-nodes-tmux-orchestrator
Version:
n8n nodes for orchestrating Claude AI agents through tmux sessions
106 lines • 3.57 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.modelManager = exports.ModelManager = void 0;
class ModelManager {
constructor(config = {}) {
this.cachedModels = null;
this.lastFetch = null;
this.knownModels = [
{
name: 'Sonnet (Latest)',
value: 'sonnet',
description: 'Latest Sonnet model',
isRecommended: true,
},
{
name: 'Opus (Latest)',
value: 'opus',
description: 'Latest Opus model',
isRecommended: true,
},
];
this.legacyModels = [];
this.cacheDuration = config.cacheDuration || 60;
}
static getInstance(config) {
if (!ModelManager.instance) {
ModelManager.instance = new ModelManager(config);
}
return ModelManager.instance;
}
async getAvailableModels(config = {}) {
if (this.isCacheValid()) {
return this.cachedModels;
}
try {
const models = await this.fetchLatestModels(config);
this.cachedModels = models;
this.lastFetch = new Date();
return models;
}
catch (error) {
console.warn('Failed to fetch latest models, using known models:', error.message);
return this.getKnownModels(config);
}
}
async getModelOptions(config = {}) {
const models = await this.getAvailableModels(config);
return models.map(model => ({
name: model.name,
value: model.value,
}));
}
async isValidModel(modelValue) {
const models = await this.getAvailableModels();
return models.some(model => model.value === modelValue);
}
async getRecommendedModel() {
const models = await this.getAvailableModels();
const recommended = models.find(model => model.isRecommended);
return recommended || models[0];
}
async getModelByValue(value) {
const models = await this.getAvailableModels();
return models.find(model => model.value === value) || null;
}
isCacheValid() {
if (!this.cachedModels || !this.lastFetch) {
return false;
}
const now = new Date();
const diffInMinutes = (now.getTime() - this.lastFetch.getTime()) / (1000 * 60);
return diffInMinutes < this.cacheDuration;
}
async fetchLatestModels(config) {
await new Promise(resolve => setTimeout(resolve, 100));
return this.getKnownModels(config);
}
getKnownModels(config = {}) {
let models = [...this.knownModels];
if (config.includeDeprecated !== false) {
models = [...models, ...this.legacyModels];
}
models.sort((a, b) => {
if (a.isRecommended && !b.isRecommended)
return -1;
if (!a.isRecommended && b.isRecommended)
return 1;
return a.name.localeCompare(b.name);
});
return models;
}
clearCache() {
this.cachedModels = null;
this.lastFetch = null;
}
getClaudeCommandOptions(model) {
const modelMappings = {
'sonnet': '--model sonnet',
'opus': '--model opus',
};
return modelMappings[model] || `--model ${model}`;
}
}
exports.ModelManager = ModelManager;
exports.modelManager = ModelManager.getInstance();
//# sourceMappingURL=modelManager.js.map