All files / src/llm-orchestration llm-orchestration.module.ts

100% Statements 76/76
100% Branches 0/0
100% Functions 6/6
100% Lines 74/74

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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 2086x 6x 6x 6x 6x 6x 6x 6x 6x   6x 6x 6x 6x           6x   6x 6x 6x 6x 6x 6x 6x 6x     6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x     6x 6x 6x 6x         18x 18x 18x       18x                                                                                                                                   6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x                                                                     6x                                 6x  
import { Module, forwardRef } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { LlmOutputParserService } from './parser/llm-output-parser.service';
import { LlmTurnProcessorService } from './llm-turn-processor.service';
import { ToolSchemaService } from './tool-schema.service';
import { HistoryCompressionService } from './history-compression.service';
import { AIActionsModule } from '../ai-actions/ai-actions.module';
import { SessionInputsModule } from '../session-inputs/session-inputs.module';
import { InteractiveChatModule } from '../interactive-chat/chat.module';
// Added EventsModule
import { EventsModule } from '../events/events.module';
import { ApplicationStateModule } from '../application-state/application-state.module';
import { MessageBusModule } from '../message-bus/message-bus.module';
import {
  AIAction,
  SessionInput,
  Session,
  SystemPrompt,
} from '../core-entities';
import { ExecutionLogsModule } from '../execution-logs/execution-logs.module';
// Added missing modules
import { SystemPromptsModule } from '../system-prompts/system-prompts.module';
import { SessionsModule } from '../sessions/sessions.module';
import { WorkspaceModule } from '../workspace/workspace.module';
import { McpModule } from '../mcp/mcp.module';
import { SubAgentsModule } from '../sub-agents/sub-agents.module';
import { ToolHooksModule } from '../tool-hooks/tool-hooks.module';
import { SyntaxValidationModule } from '../syntax-validation/syntax-validation.module';
import { ContextGenerationModule } from '../context-generation/context-generation.module';
 
// Action Handlers
import { CreateFileHandler } from './action-handlers/create-file.handler';
import { DeleteFileHandler } from './action-handlers/delete-file.handler';
import { OverwriteFileHandler } from './action-handlers/overwrite-file.handler';
import { RunCommandHandler } from './action-handlers/run-command.handler';
import { RequestContextHandler } from './action-handlers/request-context.handler';
import { FinalHandler } from './action-handlers/final.handler';
import { QuickEditHandler } from './action-handlers/quick-edit.handler';
import { ApplyDiffHandler } from './action-handlers/apply-diff.handler';
import { PatchHandler } from './action-handlers/patch.handler';
import { NewSessionHandler } from './action-handlers/new-session.handler';
import { WriteTodoHandler } from './action-handlers/write-todo.handler';
import { ExecuteCodeHandler } from './action-handlers/execute-code.handler';
import { HowtoHandler } from './action-handlers/howto.handler';
import { InvokeSubAgentHandler } from './action-handlers/invoke-subagent.handler';
import { ListSubAgentsHandler } from './action-handlers/list-sub-agents.handler';
import { GetSessionHistoryHandler } from './action-handlers/get-session-history.handler';
import { GenerateTitleHandler } from './action-handlers/generate-title.handler';
import { AskUserHandler } from './action-handlers/ask-user.handler';
import { GetMessagesHandler } from './action-handlers/get-messages.handler';
import { DiscardMessagesHandler } from './action-handlers/discard-messages.handler';
 
// Hooks
import { InvalidToolFeedbackHook } from './hooks/invalid-tool-feedback.hook';
import { FrontendNotificationHook } from './hooks/frontend-notification.hook';
import { FollowUpPostExecutionHook } from './hooks/follow-up-post-execution.hook';
import { YoloModePostExecutionHook } from './hooks/yolo-mode-post-execution.hook';
 
@Module({
  imports: [
    TypeOrmModule.forFeature([AIAction, SessionInput, Session, SystemPrompt]),
    forwardRef(() => AIActionsModule),
    forwardRef(() => SessionInputsModule),
    forwardRef(() => InteractiveChatModule),
    EventsModule,
    MessageBusModule,
    // Added missing imports
    forwardRef(() => SystemPromptsModule),
    SessionsModule,
    ApplicationStateModule,
    ExecutionLogsModule,
    WorkspaceModule,
    McpModule,
    SubAgentsModule,
    ToolHooksModule,
    SyntaxValidationModule,
    ContextGenerationModule,
  ],
  providers: [
    LlmOutputParserService,
    LlmTurnProcessorService,
    ToolSchemaService,
    HistoryCompressionService,
    // Handlers
    CreateFileHandler,
    DeleteFileHandler,
    OverwriteFileHandler,
    RunCommandHandler,
    RequestContextHandler,
    FinalHandler,
    QuickEditHandler,
    ApplyDiffHandler,
    PatchHandler,
    NewSessionHandler,
    WriteTodoHandler,
    ExecuteCodeHandler,
    HowtoHandler,
    InvokeSubAgentHandler,
    ListSubAgentsHandler,
    GetSessionHistoryHandler,
    GenerateTitleHandler,
    AskUserHandler,
    GetMessagesHandler,
    DiscardMessagesHandler,
    // Hooks
    InvalidToolFeedbackHook,
    FrontendNotificationHook,
    FollowUpPostExecutionHook,
    YoloModePostExecutionHook,
    {
      provide: 'ACTION_HANDLER_REGISTRY',
      useFactory: (
        createFile: CreateFileHandler,
        deleteFile: DeleteFileHandler,
        overwriteFile: OverwriteFileHandler,
        runCommand: RunCommandHandler,
        requestContext: RequestContextHandler,
        final: FinalHandler,
        quickEdit: QuickEditHandler,
        applyDiff: ApplyDiffHandler,
        patch: PatchHandler,
        newSession: NewSessionHandler,
        writeTodo: WriteTodoHandler,
        executeCode: ExecuteCodeHandler,
        howto: HowtoHandler,
        invokeSubAgent: InvokeSubAgentHandler,
        listSubAgents: ListSubAgentsHandler,
        getSessionHistory: GetSessionHistoryHandler,
        generateTitle: GenerateTitleHandler,
        askUser: AskUserHandler,
        getMessages: GetMessagesHandler,
        discardMessages: DiscardMessagesHandler,
      ) => {
        const registry = new Map();
        registry.set(createFile.toolName, createFile);
        registry.set(deleteFile.toolName, deleteFile);
        registry.set(overwriteFile.toolName, overwriteFile);
        registry.set(runCommand.toolName, runCommand);
        registry.set(requestContext.toolName, requestContext);
        registry.set(final.toolName, final);
        registry.set(quickEdit.toolName, quickEdit);
        registry.set(applyDiff.toolName, applyDiff);
        registry.set(patch.toolName, patch);
        registry.set(newSession.toolName, newSession);
        registry.set(writeTodo.toolName, writeTodo);
        registry.set(executeCode.toolName, executeCode);
        registry.set(howto.toolName, howto);
        registry.set(invokeSubAgent.toolName, invokeSubAgent);
        registry.set(listSubAgents.toolName, listSubAgents);
        registry.set(getSessionHistory.toolName, getSessionHistory);
        registry.set(generateTitle.toolName, generateTitle);
        registry.set(askUser.toolName, askUser);
        registry.set(getMessages.toolName, getMessages);
        registry.set(discardMessages.toolName, discardMessages);
        return registry;
      },
      inject: [
        CreateFileHandler,
        DeleteFileHandler,
        OverwriteFileHandler,
        RunCommandHandler,
        RequestContextHandler,
        FinalHandler,
        QuickEditHandler,
        ApplyDiffHandler,
        PatchHandler,
        NewSessionHandler,
        WriteTodoHandler,
        ExecuteCodeHandler,
        HowtoHandler,
        InvokeSubAgentHandler,
        ListSubAgentsHandler,
        GetSessionHistoryHandler,
        GenerateTitleHandler,
        AskUserHandler,
        GetMessagesHandler,
        DiscardMessagesHandler,
      ],
    },
    {
      provide: 'POST_EXECUTION_HOOKS',
      useFactory: (
        invalidTool: InvalidToolFeedbackHook,
        frontendNotification: FrontendNotificationHook,
        followUp: FollowUpPostExecutionHook,
        yoloMode: YoloModePostExecutionHook,
      ) => {
        // Order matters! Sub-agent results are now handled synchronously
        // by InvokeSubAgentHandler, so SubAgentFinalResponseHook is removed.
        return [invalidTool, yoloMode, followUp, frontendNotification];
      },
      inject: [
        InvalidToolFeedbackHook,
        FrontendNotificationHook,
        FollowUpPostExecutionHook,
        YoloModePostExecutionHook,
      ],
    },
  ],
  exports: [
    LlmTurnProcessorService,
    ToolSchemaService,
    HistoryCompressionService,
    'ACTION_HANDLER_REGISTRY',
  ],
})
export class LlmOrchestrationModule {}