# All files / modules/book-generator/strategies selector.ts

0% Statements 0/29
0% Branches 0/1
0% Functions 0/1
0% Lines 0/29

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

     /**
     * 策略选择器
     * 通过配置决定使用哪个生成策略
     */

    import { GenerationStrategy, StrategyConfig, StrategyName } from './types';
    import { SequentialStrategy } from './sequential.strategy';
    import { OneStepOutlineStrategy } from './one-step-outline.strategy';
    import { PerChapterStrategy } from './per-chapter.strategy';
    import { DeepPlanParallelStrategy } from './deep-plan-parallel.strategy';

    // ============ 策略注册 ============

    const STRATEGIES: Record<StrategyName, GenerationStrategy> = {
      'sequential': new SequentialStrategy(),
      'one-step-outline': new OneStepOutlineStrategy(),
      'per-chapter': new PerChapterStrategy(),
      'deep-plan-parallel': new DeepPlanParallelStrategy(),
    };

    // ============ 默认配置 ============

    /**
     * 当前激活的策略名称
     * 可通过修改此配置切换生成方案，然后重新运行
     *
     * 可选值：
     *   'sequential'          - 串行（原始方案）
     *   'one-step-outline'     - 一步大纲 + 并行内容
     *   'per-chapter'          - 逐章内聚（内容质量好）
     *   'deep-plan-parallel'   - DeepPlan+RichOutline+Concurrent+Edit（当前推荐，最新策略）
     */
    const DEFAULT_STRATEGY: StrategyName = 'deep-plan-parallel';

    // ============ 选择 ============

    let currentStrategy: StrategyName = DEFAULT_STRATEGY;

    /**
     * 获取当前策略名称
     */
    export function getCurrentStrategyName(): StrategyName {
      return currentStrategy;
    }

    /**
     * 切换当前策略（运行时切换，立即生效）
     */
    export function setCurrentStrategy(name: StrategyName): void {
      if (STRATEGIES[name]) {
        currentStrategy = name;
        console.log(`[StrategySelector] 切换到策略: ${name} - ${STRATEGIES[name].description}`);
      } else {
        console.warn(`[StrategySelector] 未知策略: ${name}，保持当前: ${currentStrategy}`);
      }
    }

    /**
     * 获取当前策略实例
     */
    export function getCurrentStrategy(): GenerationStrategy {
      return STRATEGIES[currentStrategy] || STRATEGIES['sequential'];
    }

    /**
     * 获取所有可用策略列表
     */
    export function getAllStrategies(): GenerationStrategy[] {
      return Object.values(STRATEGIES);
    }

    /**
     * 根据名称获取策略
     */
    export function getStrategy(name: StrategyName): GenerationStrategy {
      return STRATEGIES[name] || STRATEGIES['sequential'];
    }

    /** 重新导出类型 */
    export type { StrategyName, StrategyConfig } from './types';