@@ -12,7 +12,7 @@ import {
1212 getMainWorktreeFromWorktree ,
1313} from "@/git" ;
1414import { removeWorktreeSafe , removeWorktree , pruneWorktrees } from "@/services/gitService" ;
15- import type { AIService } from "@/services/aiService" ;
15+ import { AIService } from "@/services/aiService" ;
1616import { HistoryService } from "@/services/historyService" ;
1717import { PartialService } from "@/services/partialService" ;
1818import { AgentSession } from "@/services/agentSession" ;
@@ -45,7 +45,7 @@ export class IpcMain {
4545 private readonly config : Config ;
4646 private readonly historyService : HistoryService ;
4747 private readonly partialService : PartialService ;
48- private _aiService : AIService | null = null ;
48+ private readonly aiService : AIService ;
4949 private readonly sessions = new Map < string , AgentSession > ( ) ;
5050 private readonly sessionSubscriptions = new Map <
5151 string ,
@@ -58,27 +58,7 @@ export class IpcMain {
5858 this . config = config ;
5959 this . historyService = new HistoryService ( config ) ;
6060 this . partialService = new PartialService ( config , this . historyService ) ;
61- // Don't create AIService here - it imports the massive "ai" package (~3s load time)
62- // Create it on-demand when first needed
63- }
64-
65- /**
66- * Lazy-load AIService on first use.
67- * AIService imports the entire AI SDK which is ~3s load time.
68- * By deferring this until first actual use, we keep startup fast.
69- */
70- private get aiService ( ) : AIService {
71- if ( ! this . _aiService ) {
72- // Dynamic import to avoid loading AI SDK at startup
73- // Use relative path (not @/ alias) because require() runs at runtime after TS compilation
74- // This is safe because AIService is only accessed after IPC handlers are registered
75- /* eslint-disable-next-line @typescript-eslint/no-require-imports */
76- const { AIService : AIServiceClass } = require ( "./aiService" ) as {
77- AIService : typeof AIService ;
78- } ;
79- this . _aiService = new AIServiceClass ( this . config , this . historyService , this . partialService ) ;
80- }
81- return this . _aiService ;
61+ this . aiService = new AIService ( config , this . historyService , this . partialService ) ;
8262 }
8363
8464 private getOrCreateSession ( workspaceId : string ) : AgentSession {
0 commit comments