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
+7
View File
@@ -114,6 +114,13 @@ export function createClientFromConfig(cfg: ModelConfig): ModelClient {
model: cfg.model,
apiKey: cfg.api_key,
endpoint: cfg.endpoint,
onLoginRequired: async () => {
const { loginGitHub } = await import('../auth/index.js');
return loginGitHub((userCode, verificationUri) => {
console.log(`GitHub login required. Visit: ${verificationUri}`);
console.log(`Enter code: ${userCode}`);
});
},
});
default:
throw new Error(`Unknown model provider: ${(cfg as Record<string, unknown>).provider}`);