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