All files / services/crawler-api/src/models CrawlerConfig.js

100% Statements 82/82
100% Branches 1/1
100% Functions 0/0
100% Lines 82/82

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 821x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x
const mongoose = require('mongoose');
 
const crawlerConfigSchema = new mongoose.Schema({
  userId: {
    type: String,
    required: true,
    index: true,
  },
  organizationId: {
    type: String,
    required: true,
    index: true,
  },
  name: {
    type: String,
    required: true,
  },
  description: {
    type: String,
    default: '',
  },
  // Prompt utilisé pour :
  // 1. L'évaluation de pertinence des pages (evaluatePage)
  // 2. La synthèse des faits SI extractPrompt n'est pas défini
  prompt: {
    type: String,
    default: '',
  },
  // Prompt utilisé pour la synthèse des faits UNIQUEMENT.
  // Si défini, remplace prompt pour l'étape de synthèse.
  // L'évaluation de pertinence utilise toujours prompt.
  extractPrompt: {
    type: String,
    default: '',
  },
  startUrl: {
    type: String,
    default: '',
  },
  config: {
    maxPages: { type: Number, default: 10 },
    maxDepth: { type: Number, default: 3 },
    
    pageThreshold: { type: Number, default: 60 },
    linkThreshold: { type: Number, default: 40 },
    
    crawlDelay: { type: Number, default: 100 },
    
    llmModel: { type: String, default: 'deepseek/deepseek-v4-flash' },
    sameDomain: { type: Boolean, default: false },
    enableSynthesis: { type: Boolean, default: true },
    // Configuration du synthétiseur pour les workflows réutilisables (API workflow).
    // Dans le flux crawler, ce champ n'est PAS utilisé — seuls prompt et extractPrompt
    // (champs racine) sont lus. Ce bloc est conservé pour compatibilité future :
    // quand un workflow sera créé manuellement via l'API workflow, synthetiser.spec
    // (instruction, maxFacts, schema, etc.) sera exploité directement.
    // Voir services/workflow-api/src/index.js POST /:orgId/workflow/extract
    synthetiser: {
      mode: { type: String, enum: ['fact', 'data'], default: 'fact' },
      spec: { type: mongoose.Schema.Types.Mixed, default: {} }
    },
    
    // Router configuration for routing facts to knowledge bases
    // Format: [{ type: "meilisearch", id: "kb-id" }, ...]
    router: { type: mongoose.Schema.Types.Mixed, default: [] },
  },
  isActive: {
    type: Boolean,
    default: true,
  },
  runCount: {
    type: Number,
    default: 0,
  },
}, {
  timestamps: true,
});
 
crawlerConfigSchema.index({ userId: 1, createdAt: -1 });
crawlerConfigSchema.index({ organizationId: 1, createdAt: -1 });
 
module.exports = mongoose.model('CrawlerConfig', crawlerConfigSchema, 'crawlerconfigs');