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:
+14
-1
@@ -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}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user