feat: add auto-login for GitHub Copilot when no token is available

GitHubModelsClient now lazily resolves tokens at first API call. If no
token exists (env var, stored OAuth, or config), it triggers the OAuth
device flow automatically via an onLoginRequired callback wired in both
the TUI and daemon entry points.
This commit is contained in:
William Valentin
2026-02-06 22:33:48 -08:00
parent f363717f5f
commit 73fc5d173d
3 changed files with 76 additions and 5 deletions
+14 -1
View File
@@ -74,7 +74,20 @@ export function registerTuiCommand(program: Command): void {
case 'bedrock':
return new BedrockClient({ model: cfg.model, region: cfg.endpoint, accessKeyId: cfg.api_key, secretAccessKey: cfg.auth_token });
case 'github':
return new GitHubModelsClient({ model: cfg.model, apiKey: cfg.api_key, endpoint: cfg.endpoint });
return new GitHubModelsClient({
model: cfg.model,
apiKey: cfg.api_key,
endpoint: cfg.endpoint,
onLoginRequired: async () => {
const { loginGitHub } = await import('../auth/index.js');
console.log('\nGitHub authentication required. Starting login flow...');
return loginGitHub((userCode, verificationUri) => {
console.log(`\nVisit: ${verificationUri}`);
console.log(`Enter code: ${userCode}\n`);
console.log('Waiting for authorization...');
});
},
});
default:
throw new Error(`Unknown provider: ${cfg.provider}`);
}