fixed cred selector

This commit is contained in:
waleed
2026-03-25 09:14:42 -07:00
parent 1b25460a62
commit 5ef91e56b8
3 changed files with 22 additions and 4 deletions

View File

@@ -13,6 +13,7 @@ import type { BreadcrumbItem } from '@/app/workspace/[workspaceId]/components'
import { ResourceHeader } from '@/app/workspace/[workspaceId]/components'
import { useAgent, useDeleteAgent, useUpdateAgent } from '@/hooks/queries/agents'
import { useInlineRename } from '@/hooks/use-inline-rename'
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
const logger = createLogger('AgentDetail')
@@ -37,6 +38,17 @@ export function AgentDetail({ agentId, workspaceId }: AgentDetailProps) {
const saveTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null)
const isInitializedRef = useRef(false)
// SubBlockStore.setValue reads activeWorkflowId from the workflow registry and no-ops when null.
// Set the agentId as the active "workflow" so tool sub-block params (credentials, etc.) persist.
useEffect(() => {
useWorkflowRegistry.setState({ activeWorkflowId: agentId })
return () => {
if (useWorkflowRegistry.getState().activeWorkflowId === agentId) {
useWorkflowRegistry.setState({ activeWorkflowId: null })
}
}
}, [agentId])
useEffect(() => {
if (agent && !isInitializedRef.current) {
setLocalConfig(agent.config ?? {})

View File

@@ -51,7 +51,10 @@ export function CredentialSelector({
const [showOAuthModal, setShowOAuthModal] = useState(false)
const [editingValue, setEditingValue] = useState('')
const [isEditing, setIsEditing] = useState(false)
const { activeWorkflowId } = useWorkflowRegistry()
const { activeWorkflowId, workflows } = useWorkflowRegistry()
// Only pass workflowId when it's a real registered workflow (not an agent ID set as the active context)
const effectiveWorkflowId =
activeWorkflowId && workflows[activeWorkflowId] ? activeWorkflowId : undefined
const [storeValue, setStoreValue] = useSubBlockValue<string | null>(blockId, subBlock.id)
const requiredScopes = subBlock.requiredScopes || []
@@ -101,7 +104,7 @@ export function CredentialSelector({
} = useOAuthCredentials(effectiveProviderId, {
enabled: Boolean(effectiveProviderId),
workspaceId,
workflowId: activeWorkflowId || undefined,
workflowId: effectiveWorkflowId,
})
const selectedCredential = useMemo(

View File

@@ -72,7 +72,10 @@ export function ToolCredentialSelector({
const [showOAuthModal, setShowOAuthModal] = useState(false)
const [editingInputValue, setEditingInputValue] = useState('')
const [isEditing, setIsEditing] = useState(false)
const { activeWorkflowId } = useWorkflowRegistry()
const { activeWorkflowId, workflows } = useWorkflowRegistry()
// Only pass workflowId when it's a real registered workflow (not an agent ID set as the active context)
const effectiveWorkflowId =
activeWorkflowId && workflows[activeWorkflowId] ? activeWorkflowId : undefined
const selectedId = value || ''
const effectiveLabel = label || `Select ${getProviderName(provider)} account`
@@ -86,7 +89,7 @@ export function ToolCredentialSelector({
} = useOAuthCredentials(effectiveProviderId, {
enabled: Boolean(effectiveProviderId),
workspaceId,
workflowId: activeWorkflowId || undefined,
workflowId: effectiveWorkflowId,
})
const selectedCredential = useMemo(