fix: integrate Claude CLI provider state
This commit is contained in:
@@ -20,6 +20,7 @@ import {
|
||||
firstUnansweredPrompt,
|
||||
parseAuthPrompts,
|
||||
parseAuthorization,
|
||||
shouldOpenAuthorizationUrl,
|
||||
visiblePrompts,
|
||||
type AuthPrompt,
|
||||
type OAuthAuthorization,
|
||||
@@ -173,7 +174,10 @@ export const ProviderOAuthMethods: React.FC<ProviderOAuthMethodsProps> = ({
|
||||
return;
|
||||
}
|
||||
|
||||
if (authorization.url) {
|
||||
// Claude Code CLI owns its OAuth flow and opens the browser itself. Its
|
||||
// plugin URL is informational only; opening it creates a misleading docs
|
||||
// tab alongside the real sign-in page.
|
||||
if (authorization.url && shouldOpenAuthorizationUrl(providerId, authorization.url)) {
|
||||
void openExternalUrl(authorization.url);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
getOAuthAuthMethods,
|
||||
normalizeAuthType,
|
||||
parseAuthPayload,
|
||||
requiresOpenCodeRestartAfterOAuth,
|
||||
shouldShowApiKeyAuth,
|
||||
} from './providerAuth';
|
||||
|
||||
@@ -57,4 +58,9 @@ describe('provider auth method helpers', () => {
|
||||
{ method: { type: 'oauth', label: 'Cursor' }, methodIndex: 0 },
|
||||
]);
|
||||
});
|
||||
|
||||
test('Claude CLI OAuth does not require an OpenCode restart', () => {
|
||||
expect(requiresOpenCodeRestartAfterOAuth('claude-code')).toBe(false);
|
||||
expect(requiresOpenCodeRestartAfterOAuth('github-copilot')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -27,6 +27,7 @@ import { shouldLoadAvailableProviders } from './providerAvailability';
|
||||
import {
|
||||
getOAuthAuthMethods,
|
||||
parseAuthPayload,
|
||||
requiresOpenCodeRestartAfterOAuth,
|
||||
shouldShowApiKeyAuth,
|
||||
type AuthMethod,
|
||||
type OAuthAuthMethodEntry,
|
||||
@@ -471,7 +472,9 @@ export const ProvidersPage: React.FC = () => {
|
||||
|
||||
const handleOAuthConnected = (providerId: string) => {
|
||||
setShowAuthPanel(false);
|
||||
recordDeferredOpenCodeRestart('providers', { id: providerId });
|
||||
if (requiresOpenCodeRestartAfterOAuth(providerId)) {
|
||||
recordDeferredOpenCodeRestart('providers', { id: providerId });
|
||||
}
|
||||
setSelectedProvider(providerId);
|
||||
};
|
||||
|
||||
|
||||
@@ -7,11 +7,19 @@ import {
|
||||
isPromptVisible,
|
||||
parseAuthPrompts,
|
||||
parseAuthorization,
|
||||
shouldOpenAuthorizationUrl,
|
||||
visiblePrompts,
|
||||
type AuthPrompt,
|
||||
type ProviderOAuthTranslator,
|
||||
} from './provider-oauth';
|
||||
|
||||
describe('shouldOpenAuthorizationUrl', () => {
|
||||
test('lets Claude Code CLI own browser launch', () => {
|
||||
expect(shouldOpenAuthorizationUrl('claude-code', 'https://docs.example')).toBe(false);
|
||||
expect(shouldOpenAuthorizationUrl('github-copilot', 'https://github.com/login')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
/** Mirrors the github-copilot auth method shipped by OpenCode. */
|
||||
const copilotPrompts = [
|
||||
{
|
||||
|
||||
@@ -29,6 +29,9 @@ export interface OAuthAuthorization {
|
||||
userCode?: string;
|
||||
}
|
||||
|
||||
export const shouldOpenAuthorizationUrl = (providerId: string, url?: string): boolean =>
|
||||
Boolean(url) && providerId !== 'claude-code';
|
||||
|
||||
export interface AuthPromptOption {
|
||||
label: string;
|
||||
value: string;
|
||||
|
||||
@@ -57,3 +57,6 @@ export const getOAuthAuthMethods = (methods: AuthMethod[]): OAuthAuthMethodEntry
|
||||
methods
|
||||
.map((method, methodIndex) => ({ method, methodIndex }))
|
||||
.filter(({ method }) => normalizeAuthType(method) === 'oauth');
|
||||
|
||||
export const requiresOpenCodeRestartAfterOAuth = (providerId: string): boolean =>
|
||||
providerId !== 'claude-code';
|
||||
|
||||
Reference in New Issue
Block a user