From 6d961ccd722b5b58ace344434837a2e920739238 Mon Sep 17 00:00:00 2001 From: Chris Scott <99081550+chriswritescode-dev@users.noreply.github.com> Date: Wed, 15 Apr 2026 16:39:07 -0400 Subject: [PATCH] fix: improve OAuth dialog UX and fix session state management - Add auto-start authorization for single-method OAuth providers - Fix optimistic message cleanup on error in useSendPrompt - Add JSON Pointer path decoding for validation errors - Improve OAuth dialog responsive layout and truncate long labels - Change onSuccess to onSettled for proper query invalidation --- backend/src/services/proxy.ts | 9 ++++ .../settings/OAuthAuthorizeDialog.tsx | 49 +++++++++++++------ frontend/src/hooks/useOpenCode.ts | 16 +++--- 3 files changed, 53 insertions(+), 21 deletions(-) diff --git a/backend/src/services/proxy.ts b/backend/src/services/proxy.ts index 633609f8..79cd9ff3 100644 --- a/backend/src/services/proxy.ts +++ b/backend/src/services/proxy.ts @@ -67,6 +67,15 @@ function getIssuePath(value: unknown): string { } if (typeof value === 'string' && value.length > 0) { + if (value.startsWith('/')) { + const pointerPath = value + .split('/') + .filter(Boolean) + .map((part) => part.replace(/~1/g, '/').replace(/~0/g, '~')) + .join('.') + return pointerPath || 'root' + } + return value } diff --git a/frontend/src/components/settings/OAuthAuthorizeDialog.tsx b/frontend/src/components/settings/OAuthAuthorizeDialog.tsx index 4decf2b2..f9d5085f 100644 --- a/frontend/src/components/settings/OAuthAuthorizeDialog.tsx +++ b/frontend/src/components/settings/OAuthAuthorizeDialog.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react' +import { useState, useMemo, useEffect, useCallback } from 'react' import { Button } from '@/components/ui/button' import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@/components/ui/dialog' import { Input } from '@/components/ui/input' @@ -61,10 +61,22 @@ export function OAuthAuthorizeDialog({ const [error, setError] = useState(null) const [selectedMethodIndex, setSelectedMethodIndex] = useState(null) const [promptInputs, setPromptInputs] = useState>>({}) + const [autoStarted, setAutoStarted] = useState(false) - const getMethodInputs = (methodIndex: number) => promptInputs[methodIndex] || {} + const getMethodInputs = useCallback((methodIndex: number) => promptInputs[methodIndex] || {}, [promptInputs]) - const handleAuthorize = async (methodIndex: number) => { + const oauthMethods = useMemo(() => { + return methods + .flatMap((method, index) => method.type === 'oauth' ? [{ method, index }] : []) + .filter(({ method }: { method: ProviderAuthMethod }) => { + if (providerId === 'openai' && isBrowserLocalMethod(method)) { + return false + } + return true + }) + }, [methods, providerId]) + + const handleAuthorize = useCallback(async (methodIndex: number) => { const method = methods[methodIndex] const methodInputs = getMethodInputs(methodIndex) const visiblePrompts = getVisiblePrompts(method, methodInputs) @@ -93,7 +105,18 @@ export function OAuthAuthorizeDialog({ } finally { setIsLoading(false) } - } + }, [methods, providerId, onSuccess, getMethodInputs]) + + useEffect(() => { + if (open && oauthMethods.length === 1 && !autoStarted && !isLoading) { + const { index } = oauthMethods[0] + setAutoStarted(true) + setSelectedMethodIndex(index) + if (!hasPrompts(methods[index])) { + void handleAuthorize(index) + } + } + }, [open, oauthMethods, autoStarted, isLoading, methods, handleAuthorize]) const handleMethodSelection = (methodIndex: number) => { setError(null) @@ -121,11 +144,9 @@ export function OAuthAuthorizeDialog({ onOpenChange(false) } - const oauthMethods = methods.flatMap((method, index) => method.type === 'oauth' ? [{ method, index }] : []) - return ( - + Connect to {providerName} @@ -148,25 +169,25 @@ export function OAuthAuthorizeDialog({ return (
-
+
{isBrowserLocal && ( - + Localhost only )}
{selectedMethodIndex === index && hasPrompts(method) && ( -
+
{visiblePrompts.map((prompt) => ( prompt.type === 'text' ? (
@@ -214,7 +235,7 @@ export function OAuthAuthorizeDialog({ )} {isBrowserLocal && ( -

+

This method relies on a callback server started by OpenCode and may not work when OCM is remote.

)} diff --git a/frontend/src/hooks/useOpenCode.ts b/frontend/src/hooks/useOpenCode.ts index 90ce9ebb..8f0e1612 100644 --- a/frontend/src/hooks/useOpenCode.ts +++ b/frontend/src/hooks/useOpenCode.ts @@ -29,6 +29,8 @@ export function useTitleGenerating(sessionID: string | undefined) { ); useEffect(() => { + setIsGenerating(sessionID ? titleGeneratingSessionsState.has(sessionID) : false); + const listener = () => { setIsGenerating(sessionID ? titleGeneratingSessionsState.has(sessionID) : false); }; @@ -155,7 +157,7 @@ export const useDeleteSession = (opcodeUrl: string | null | undefined, directory return results }, - onSuccess: () => { + onSettled: () => { queryClient.invalidateQueries({ queryKey: ["opencode", "sessions", opcodeUrl, directory] }); }, }); @@ -366,6 +368,12 @@ export const useSendPrompt = (opcodeUrl: string | null | undefined, directory?: onError: (error, variables) => { const { sessionID } = variables; const messagesQueryKey = ["opencode", "messages", opcodeUrl, sessionID, directory]; + + setSessionStatus(sessionID, { type: "idle" }); + queryClient.setQueryData( + messagesQueryKey, + (old) => old?.filter((msgWithParts) => !msgWithParts.info.id.startsWith("optimistic_")), + ); const isNetworkError = error instanceof TypeError || (error instanceof FetchError && error.code === 'TIMEOUT'); @@ -381,12 +389,6 @@ export const useSendPrompt = (opcodeUrl: string | null | undefined, directory?: return; } - setSessionStatus(sessionID, { type: "idle" }); - queryClient.setQueryData( - messagesQueryKey, - (old) => old?.filter((msgWithParts) => !msgWithParts.info.id.startsWith("optimistic_")), - ); - const parsed = parseNetworkError(error); showToast.error(parsed.title, { description: parsed.message,