import { getQueryClient } from '@/app/_shell/providers/get-query-client' import { getWorkflowListQueryOptions } from '@/hooks/queries/utils/workflow-list-query' import { useWorkflowRegistry } from '@/stores/workflows/registry/store' interface SubBlockOption { label: string id: string } /** * Loads the active workspace's workflows for multi-select subblocks * (`fetchOptions`). Set `excludeActiveWorkflow` for surfaces where selecting * the current workflow is meaningless (e.g. the Sim trigger never receives * events about itself). */ export async function fetchWorkspaceWorkflowOptions(options?: { excludeActiveWorkflow?: boolean }): Promise { const registry = useWorkflowRegistry.getState() const workspaceId = registry.hydration.workspaceId if (!workspaceId) return [] const workflows = await getQueryClient().fetchQuery( getWorkflowListQueryOptions(workspaceId, 'active') ) return workflows .filter( (workflow) => !options?.excludeActiveWorkflow || workflow.id !== registry.activeWorkflowId ) .map((workflow) => ({ id: workflow.id, label: workflow.name })) }