MCPcopy
hub / github.com/simstudioai/sim / useWorkflowStates

Function useWorkflowStates

apps/sim/hooks/queries/workflows.ts:92–109  ·  view source on GitHub ↗
(
  workflowIds: ReadonlyArray<string | undefined>
)

Source from the content-addressed store, hash-verified

90 * register their own observer.
91 */
92export function useWorkflowStates(
93 workflowIds: ReadonlyArray<string | undefined>
94): Map<string, WorkflowState | null> {
95 const uniqueIds = Array.from(new Set(workflowIds.filter((id): id is string => Boolean(id))))
96 const results = useQueries({
97 queries: uniqueIds.map((id) => ({
98 queryKey: workflowKeys.state(id),
99 queryFn: ({ signal }: { signal?: AbortSignal }) => fetchWorkflowEnvelope(id, signal),
100 select: mapWorkflowState,
101 staleTime: 30 * 1000,
102 })),
103 })
104 const map = new Map<string, WorkflowState | null>()
105 uniqueIds.forEach((id, i) => {
106 map.set(id, (results[i].data as WorkflowState | null | undefined) ?? null)
107 })
108 return map
109}
110
111export function useWorkflows(workspaceId?: string, options?: { scope?: WorkflowQueryScope }) {
112 const { scope = 'active' } = options || {}

Callers 1

useTableFunction · 0.90

Calls 3

fetchWorkflowEnvelopeFunction · 0.90
stateMethod · 0.80
setMethod · 0.65

Tested by

no test coverage detected