Skip to content

Commit 1032638

Browse files
committed
🤖 Fix: Also use dynamic import for AIService module in IpcMain
The previous commit lazy-loaded AIService instance creation, but the IpcMain module still had a static import of AIService at the top: import { AIService } from "@/services/aiService"; This meant that when loadServices() did await import("./services/ipcMain"), it would immediately trigger loading of AIService module, which then statically imports the massive "ai" package (~3s). Fix: Change to type-only import and use require() in the getter. This ensures the AI SDK is not loaded until AIService is first accessed.
1 parent 8cd13e3 commit 1032638

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/services/ipcMain.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
getMainWorktreeFromWorktree,
1313
} from "@/git";
1414
import { removeWorktreeSafe, removeWorktree, pruneWorktrees } from "@/services/gitService";
15-
import { AIService } from "@/services/aiService";
15+
import type { AIService } from "@/services/aiService";
1616
import { HistoryService } from "@/services/historyService";
1717
import { PartialService } from "@/services/partialService";
1818
import { AgentSession } from "@/services/agentSession";
@@ -69,9 +69,15 @@ export class IpcMain {
6969
*/
7070
private get aiService(): AIService {
7171
if (!this._aiService) {
72-
this._aiService = new AIService(this.config, this.historyService, this.partialService);
72+
// Dynamic import to avoid loading AI SDK at startup
73+
// This is safe because AIService is only accessed after IPC handlers are registered
74+
/* eslint-disable-next-line @typescript-eslint/no-require-imports, no-restricted-syntax */
75+
const { AIService: AIServiceClass } = require("@/services/aiService") as {
76+
AIService: typeof AIService;
77+
};
78+
this._aiService = new AIServiceClass(this.config, this.historyService, this.partialService);
7379
}
74-
return this._aiService;
80+
return this._aiService!; // Non-null assertion safe: always initialized above
7581
}
7682

7783
private getOrCreateSession(workspaceId: string): AgentSession {

0 commit comments

Comments
 (0)