feat: Integrate GitHub Copilot SDK and LangChain for provider-independent orchestration

- Added @github/copilot-sdk and related dependencies for GitHub Copilot integration.
- Implemented ChatCopilot adapter for LangChain compatibility.
- Created LLM factory to return provider-specific models (OpenAI, Anthropic, Copilot).
- Developed Orchestrator agent using LangGraph for intent routing and context assembly.
- Enhanced IPC communication for streaming AI responses to the renderer.
- Updated progress documentation with implementation details and learnings.
This commit is contained in:
Roberto Musso
2026-02-23 17:58:00 +01:00
parent c1aa6829c9
commit 00a43e0fbc
13 changed files with 1348 additions and 14 deletions

View File

@@ -1,5 +1,10 @@
import { app } from 'electron';
import { registerProvider, type AIProvider } from './provider';
// Dynamic import type — @github/copilot-sdk is ESM-only
type CopilotClientType = import('@github/copilot-sdk').CopilotClient;
let client: CopilotClientType | null = null;
let token: string | null = null;
const copilotProvider: AIProvider = {
@@ -8,13 +13,33 @@ const copilotProvider: AIProvider = {
async initialize(t: string): Promise<boolean> {
token = t;
// Actual GitHub Copilot SDK client creation will be added in US-019.
// For now, having a token means the provider is ready.
return true;
try {
// Stop existing client if re-initializing
if (client) {
// eslint-disable-next-line @typescript-eslint/no-empty-function
await client.stop().catch(() => {});
client = null;
}
const { CopilotClient } = await import('@github/copilot-sdk');
client = new CopilotClient({
githubToken: t,
autoStart: true,
autoRestart: true,
logLevel: 'warning',
});
await client.start();
console.log('[AI] CopilotClient started successfully');
return true;
} catch (err) {
console.error('[AI] Failed to start CopilotClient:', err);
client = null;
return false;
}
},
isReady(): boolean {
return token !== null;
return client !== null && token !== null;
},
};
@@ -23,4 +48,16 @@ export function getCopilotToken(): string | null {
return token;
}
/** Get the CopilotClient instance (null if not initialized). */
export function getCopilotClient(): CopilotClientType | null {
return client;
}
// Clean shutdown on app quit
app.on('before-quit', () => {
if (client) {
client.stop().catch((err: unknown) => console.error('[AI] Error stopping CopilotClient:', err));
}
});
registerProvider(copilotProvider);