Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { ChipCombobox, type ComboboxOption } from '@sim/emcn'
import { Loader } from '@sim/emcn/icons'
import { SEARCH_DEBOUNCE_MS } from '@/lib/url-state'
import { SELECTOR_CONTEXT_FIELDS } from '@/lib/workflows/subblocks/context'
import { getDependsOnFields } from '@/lib/workflows/subblocks/dependencies'
import type {
ConfigFieldMap,
ConfigFieldValue,
} from '@/app/workspace/[workspaceId]/knowledge/[id]/hooks/use-connector-config-fields'
import { getDependsOnFields } from '@/blocks/utils'
import type { ConnectorConfigField } from '@/connectors/types'
import { getSelectorDefinition } from '@/hooks/selectors/registry'
import type { SelectorContext, SelectorKey } from '@/hooks/selectors/types'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client'

import { useCallback, useMemo, useState } from 'react'
import { getDependsOnFields } from '@/blocks/utils'
import { getDependsOnFields } from '@/lib/workflows/subblocks/dependencies'
import type { ConnectorConfigField, ConnectorMeta } from '@/connectors/types'

export type ConfigFieldValue = string | string[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { Combobox, type ComboboxOption, cn } from '@sim/emcn'
import { Plus } from '@sim/emcn/icons'
import { useReactFlow } from 'reactflow'
import { getDependsOnFields } from '@/lib/workflows/subblocks/dependencies'
import { SandboxCreateModal } from '@/app/workspace/[workspaceId]/settings/components/sandboxes/components/sandbox-create-modal'
import type { SandboxLanguage } from '@/app/workspace/[workspaceId]/settings/components/sandboxes/utils'
import { shouldClearMissingOption } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/combobox/missing-option'
Expand All @@ -13,7 +14,6 @@ import { useSubBlockValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/c
import { useActiveSearchTarget } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/providers/active-search-target-provider'
import { useAccessibleReferencePrefixes } from '@/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-accessible-reference-prefixes'
import type { SubBlockConfig } from '@/blocks/types'
import { getDependsOnFields } from '@/blocks/utils'
import { usePermissionConfig } from '@/hooks/use-permission-config'
import { useSubBlockStore } from '@/stores/workflows/subblock/store'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import {
NO_DENIED_OPERATIONS,
OPERATION_SUBBLOCK_ID,
} from '@/lib/permission-groups/operation-access'
import { getDependsOnFields } from '@/lib/workflows/subblocks/dependencies'
import { formatDisplayText } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/formatted-text'
import { getWorkflowSearchLabelHighlight } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/workflow-search-highlight'
import { useFetchedOptions } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-fetched-options'
import { useSubBlockValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/hooks/use-sub-block-value'
import { useActiveSearchTarget } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/providers/active-search-target-provider'
import { getBlock } from '@/blocks/registry'
import type { SubBlockConfig } from '@/blocks/types'
import { getDependsOnFields } from '@/blocks/utils'
import { ResponseBlockHandler } from '@/executor/handlers/response/response-handler'
import { useOperationAccess } from '@/hooks/use-operation-access'
import { useWorkflowStore } from '@/stores/workflows/workflow/store'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { getWorkflowSearchDependentClears } from '@/lib/workflows/search-replace/dependencies'
import { getTransitiveSubBlockDependents } from '@/lib/workflows/subblocks/dependencies'
import { getBlock } from '@/blocks/registry'

/**
* Clear every TRANSITIVE `dependsOn` descendant of `changedParamId` in a nested tool's params,
* mirroring the top-level block clear (`use-collaborative-workflow`). Reuses the shared
* {@link getWorkflowSearchDependentClears} walk - transitive BFS plus canonical-pair expansion, so a
* {@link getTransitiveSubBlockDependents} walk - transitive BFS plus canonical-pair expansion, so a
* basic OR advanced member change clears the dependent - so both surfaces clear identically. Only
* descendants that currently hold a non-empty value are reset to `''`; the changed param itself and
* non-descendants are untouched. Returns the same reference when nothing changed.
Expand All @@ -16,7 +16,7 @@ export function clearDependentToolParams(
): Record<string, string> {
const subBlocks = getBlock(toolType)?.subBlocks ?? []
let next: Record<string, string> | null = null
for (const { subBlockId } of getWorkflowSearchDependentClears(subBlocks, changedParamId)) {
for (const { subBlockId } of getTransitiveSubBlockDependents(subBlocks, [changedParamId])) {
if (!params[subBlockId]) continue
next ??= { ...params }
next[subBlockId] = ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Button, cn, Input, toast } from '@sim/emcn'
import { ChevronDown, ChevronRight, ChevronUp, X } from '@sim/emcn/icons'
import { useParams } from 'next/navigation'
import { useShallow } from 'zustand/react/shallow'
import { getWorkflowSearchDependentClears } from '@/lib/workflows/search-replace/dependencies'
import { indexWorkflowSearchMatches } from '@/lib/workflows/search-replace/indexer'
import { buildWorkflowSearchReplacePlan } from '@/lib/workflows/search-replace/replacements'
import {
Expand All @@ -20,6 +19,7 @@ import {
import { getWorkflowSearchBlocks } from '@/lib/workflows/search-replace/state'
import { WORKFLOW_SEARCH_SUBFLOW_FIELD_IDS } from '@/lib/workflows/search-replace/subflow-fields'
import type { WorkflowSearchReplaceSubflowUpdate } from '@/lib/workflows/search-replace/types'
import { getTransitiveSubBlockDependents } from '@/lib/workflows/subblocks/dependencies'
import { useRegisterGlobalCommands } from '@/app/workspace/[workspaceId]/providers/global-commands-provider'
import { useUserPermissionsContext } from '@/app/workspace/[workspaceId]/providers/workspace-permissions-provider'
import { createCommand } from '@/app/workspace/[workspaceId]/utils/commands-utils'
Expand Down Expand Up @@ -474,10 +474,9 @@ export function WorkflowSearchReplace() {
const blockConfig = block ? getBlock(block.type) : null
if (!blockConfig?.subBlocks) continue

const dependentClears = getWorkflowSearchDependentClears(
blockConfig.subBlocks,
update.subBlockId
)
const dependentClears = getTransitiveSubBlockDependents(blockConfig.subBlocks, [
update.subBlockId,
])
for (const clear of dependentClears) {
const alreadyUpdated = batchUpdates.some(
(candidate) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
import { resolveSelectedTriggerId } from '@/lib/workflows/blocks/canvas-trigger-sentence'
import { calculateWorkflowBlockDimensions } from '@/lib/workflows/blocks/deterministic-dimensions'
import { getConditionRows, getRouterRows } from '@/lib/workflows/dynamic-handle-topology'
import { getDependsOnFields } from '@/lib/workflows/subblocks/dependencies'
import {
getDisplayValue,
hasDisplayableRowValue,
Expand Down Expand Up @@ -96,7 +97,6 @@ import {
SELECTOR_TYPES_HYDRATION_REQUIRED,
type SubBlockConfig,
} from '@/blocks/types'
import { getDependsOnFields } from '@/blocks/utils'
import { useKnowledgeBase } from '@/hooks/kb/use-knowledge'
import { useCustomTools } from '@/hooks/queries/custom-tools'
import { useDeployWorkflow } from '@/hooks/queries/deployments'
Expand Down
93 changes: 0 additions & 93 deletions apps/sim/blocks/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,10 @@ vi.mock('@/lib/oauth/utils', () => ({
getScopesForService: vi.fn(() => []),
}))

import type { SubBlockConfig } from '@/blocks/types'
import {
BUILT_IN_TOOL_TYPES,
getApiKeyCondition,
getDependsOnFields,
getSerializedModelProviderId,
getSubBlocksDependingOnChange,
parseOptionalBooleanInput,
parseOptionalJsonInput,
parseOptionalNumberInput,
Expand Down Expand Up @@ -377,96 +374,6 @@ describe('parseOptionalBooleanInput', () => {
})
})

describe('getDependsOnFields', () => {
it('returns an empty array when dependsOn is unset', () => {
expect(getDependsOnFields(undefined)).toEqual([])
})

it('returns array dependencies unchanged', () => {
expect(getDependsOnFields(['credential', 'projectId'])).toEqual(['credential', 'projectId'])
})

it('flattens all and any dependencies', () => {
expect(getDependsOnFields({ all: ['credential'], any: ['teamId', 'manualTeamId'] })).toEqual([
'credential',
'teamId',
'manualTeamId',
])
})
})

describe('getSubBlocksDependingOnChange', () => {
it('finds direct dependents of a changed subblock', () => {
const subBlocks: SubBlockConfig[] = [
{ id: 'provider', title: 'Provider', type: 'dropdown' },
{ id: 'model', title: 'Model', type: 'dropdown', dependsOn: ['provider'] },
{ id: 'prompt', title: 'Prompt', type: 'long-input' },
]

expect(
getSubBlocksDependingOnChange(subBlocks, 'provider').map((subBlock) => subBlock.id)
).toEqual(['model'])
})

it('matches dependents through canonical basic and advanced siblings', () => {
const subBlocks: SubBlockConfig[] = [
{
id: 'channel',
title: 'Channel',
type: 'channel-selector',
canonicalParamId: 'channelId',
mode: 'basic',
},
{
id: 'manualChannel',
title: 'Channel ID',
type: 'short-input',
canonicalParamId: 'channelId',
mode: 'advanced',
},
{
id: 'messageId',
title: 'Message ID',
type: 'short-input',
dependsOn: ['channelId'],
},
{
id: 'threadTs',
title: 'Thread Timestamp',
type: 'short-input',
dependsOn: ['otherField'],
},
]

expect(
getSubBlocksDependingOnChange(subBlocks, 'manualChannel').map((subBlock) => subBlock.id)
).toEqual(['messageId'])
expect(
getSubBlocksDependingOnChange(subBlocks, 'channel').map((subBlock) => subBlock.id)
).toEqual(['messageId'])
})

it('matches object-form dependencies when any listed dependency changes', () => {
const subBlocks: SubBlockConfig[] = [
{ id: 'credential', title: 'Credential', type: 'oauth-input' },
{ id: 'teamId', title: 'Team', type: 'short-input' },
{
id: 'projectId',
title: 'Project',
type: 'short-input',
dependsOn: { all: ['credential'], any: ['teamId'] },
},
]

expect(
getSubBlocksDependingOnChange(subBlocks, 'credential').map((subBlock) => subBlock.id)
).toEqual(['projectId'])
expect(
getSubBlocksDependingOnChange(subBlocks, 'teamId').map((subBlock) => subBlock.id)
).toEqual(['projectId'])
})
})

describe('getSerializedModelProviderId', () => {
const resolver = vi.mocked(getProviderFromModel)

Expand Down
34 changes: 0 additions & 34 deletions apps/sim/blocks/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
} from '@/lib/core/config/env-flags'
import { getScopesForService } from '@/lib/oauth/utils'
import { containsReference } from '@/lib/workflows/sanitization/references'
import { buildCanonicalIndex } from '@/lib/workflows/subblocks/visibility'
import type { SubBlockConfig } from '@/blocks/types'
import {
getBaseModelProviders,
Expand Down Expand Up @@ -112,39 +111,6 @@ export function getPiModelOptions() {
})
}

/**
* Gets all dependency fields as a flat array.
* Handles both simple array format and object format with all/any fields.
*/
export function getDependsOnFields(dependsOn: SubBlockConfig['dependsOn']): string[] {
if (!dependsOn) return []
if (Array.isArray(dependsOn)) return dependsOn
return [...(dependsOn.all || []), ...(dependsOn.any || [])]
}

/**
* Finds subblocks that depend on a changed field, accounting for canonical pairs.
*/
export function getSubBlocksDependingOnChange(
allSubBlocks: SubBlockConfig[],
changedSubBlockId: string
): SubBlockConfig[] {
const canonicalIndex = buildCanonicalIndex(allSubBlocks)
const canonicalId = canonicalIndex.canonicalIdBySubBlockId[changedSubBlockId]
const group = canonicalId ? canonicalIndex.groupsById[canonicalId] : undefined
const changedFields = new Set<string>([changedSubBlockId])

if (canonicalId) changedFields.add(canonicalId)
if (group?.basicId) changedFields.add(group.basicId)
for (const advancedId of group?.advancedIds || []) {
changedFields.add(advancedId)
}

return allSubBlocks.filter((subBlock) =>
getDependsOnFields(subBlock.dependsOn).some((field) => changedFields.has(field))
)
}

function getProviderFromStore(model: string): string | null {
const { providers } = useProvidersStore.getState()
const normalized = model.toLowerCase()
Expand Down
Loading
Loading