Skip to content

Commit 81d5f82

Browse files
committed
chore(cleanup): consolidate shared helpers and restore TSDoc on moved codec and subflow helpers
1 parent 841c34d commit 81d5f82

56 files changed

Lines changed: 265 additions & 289 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/docs/components/ui/block-info-card.tsx‎

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use client'
22

33
import type * as React from 'react'
4+
import { isLightTileColor } from '@sim/workflow-renderer/tile-icon-color'
45
import { blockTypeToIconMap } from '@/components/ui/icon-mapping'
56

67
interface BlockInfoCardProps {
@@ -9,33 +10,6 @@ interface BlockInfoCardProps {
910
icon?: React.ComponentType<{ className?: string }>
1011
}
1112

12-
/**
13-
* Brightness above which a tile background is "clearly light" and a white
14-
* foreground icon would wash out. Mirrors apps/sim's LIGHT_TILE_THRESHOLD
15-
* (blocks/icon-color.ts) so monochrome `currentColor` icons (e.g. Daytona,
16-
* Notion) stay legible on white/pale tiles instead of white-on-white.
17-
*/
18-
const LIGHT_TILE_THRESHOLD = 0.75
19-
20-
function isLightTileColor(color: string): boolean {
21-
const hex = color.trim().replace('#', '').toLowerCase()
22-
let r: number
23-
let g: number
24-
let b: number
25-
if (/^[0-9a-f]{3}$/.test(hex)) {
26-
r = Number.parseInt(hex[0] + hex[0], 16)
27-
g = Number.parseInt(hex[1] + hex[1], 16)
28-
b = Number.parseInt(hex[2] + hex[2], 16)
29-
} else if (/^[0-9a-f]{6}$/.test(hex)) {
30-
r = Number.parseInt(hex.slice(0, 2), 16)
31-
g = Number.parseInt(hex.slice(2, 4), 16)
32-
b = Number.parseInt(hex.slice(4, 6), 16)
33-
} else {
34-
return false
35-
}
36-
return (0.299 * r + 0.587 * g + 0.114 * b) / 255 > LIGHT_TILE_THRESHOLD
37-
}
38-
3913
export function BlockInfoCard({
4014
type,
4115
color,

‎apps/sim/app/api/v1/auth.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
import type { PersonalApiKeyPrincipal, WorkspaceApiKeyPrincipal } from '@sim/auth/principal'
2-
import { ANONYMOUS_USER_ID } from '@sim/auth/principal'
1+
import {
2+
ANONYMOUS_USER_ID,
3+
type PersonalApiKeyPrincipal,
4+
type WorkspaceApiKeyPrincipal,
5+
} from '@sim/auth/principal'
36
import { createLogger } from '@sim/logger'
47
import type { NextRequest } from 'next/server'
58
import { authenticateApiKeyFromHeader, updateApiKeyLastUsed } from '@/lib/api-key/service'

‎apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/note-block/note-block.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
type NoteSearchHighlight,
1414
type NoteSearchRange,
1515
} from '@sim/workflow-renderer'
16+
import { isWorkflowBlockProtected } from '@sim/workflow-types/workflow'
1617
import { type Node, type NodeProps, useReactFlow } from '@xyflow/react'
1718
import dynamic from 'next/dynamic'
1819
import { useShallow } from 'zustand/react/shallow'
@@ -28,7 +29,6 @@ import { useNoteImageUpload } from '@/app/workspace/[workspaceId]/w/[workflowId]
2829
import type { WorkflowBlockProps } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/types'
2930
import { useBlockVisual } from '@/app/workspace/[workspaceId]/w/[workflowId]/hooks'
3031
import { useBlockDimensions } from '@/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-block-dimensions'
31-
import { isBlockProtected } from '@/app/workspace/[workspaceId]/w/[workflowId]/utils'
3232
import { useCollaborativeWorkflow } from '@/hooks/use-collaborative-workflow'
3333
import { useIsCurrentWorkflowExecuting } from '@/stores/execution'
3434
import { usePanelEditorSearchStore, usePanelEditorStore } from '@/stores/panel'
@@ -109,7 +109,7 @@ export const NoteBlock = memo(function NoteBlock({ id, data, selected }: NodePro
109109
const isWorkflowRunning = useIsCurrentWorkflowExecuting()
110110
const canEditWorkflow = userPermissions.canEdit && !data.isWorkflowLocked
111111
const isProtected = useWorkflowStore(
112-
useCallback((state) => isBlockProtected(id, state.blocks), [id])
112+
useCallback((state) => isWorkflowBlockProtected(id, state.blocks), [id])
113113
)
114114
const clearCurrentBlock = usePanelEditorStore((state) => state.clearCurrentBlock)
115115
/* Flattened to primitives under a shallow compare, never held as the target

‎apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/tool-input/tool-input.tsx‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ import {
3434
OPERATION_SUBBLOCK_ID,
3535
} from '@/lib/permission-groups/operation-access'
3636
import { resolveStoredToolName } from '@/lib/workflows/subblocks/display'
37+
import {
38+
buildCanonicalIndex,
39+
type CanonicalIndex,
40+
type CanonicalModeOverrides,
41+
isCanonicalPair,
42+
reindexToolCanonicalModes,
43+
resolveCanonicalMode,
44+
resolveDependencyValue,
45+
scopeCanonicalModesForTool,
46+
} from '@/lib/workflows/subblocks/visibility'
3747
import { buildToolSubBlockId } from '@/lib/workflows/tool-input/synthetic-subblocks'
3848
import {
3949
buildAgentToolUsageControlCanonicalKey,
@@ -104,16 +114,6 @@ import {
104114
isUserFacingToolParam,
105115
type SubBlocksForToolInput,
106116
} from '@/tools/params'
107-
import {
108-
buildCanonicalIndex,
109-
type CanonicalIndex,
110-
type CanonicalModeOverrides,
111-
isCanonicalPair,
112-
reindexToolCanonicalModes,
113-
resolveCanonicalMode,
114-
resolveDependencyValue,
115-
scopeCanonicalModesForTool,
116-
} from '@/tools/params-resolver'
117117

118118
const logger = createLogger('ToolInput')
119119

‎apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/editor.tsx‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ import {
1212
SquareArrowUpRight,
1313
Unlock,
1414
} from '@sim/emcn/icons'
15-
import type { BlockRetryConfig } from '@sim/workflow-types/workflow'
15+
import {
16+
type BlockRetryConfig,
17+
isWorkflowBlockAncestorLocked,
18+
isWorkflowBlockProtected,
19+
} from '@sim/workflow-types/workflow'
1620
import { isEqual } from 'es-toolkit'
1721
import { useParams } from 'next/navigation'
1822
import { usePostHog } from 'posthog-js/react'
@@ -50,10 +54,6 @@ import { LoopTool } from '@/app/workspace/[workspaceId]/w/[workflowId]/component
5054
import { ParallelTool } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/subflows/parallel/parallel-config'
5155
import { getSubBlockStableKey } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/utils'
5256
import { useCurrentWorkflow } from '@/app/workspace/[workspaceId]/w/[workflowId]/hooks'
53-
import {
54-
isAncestorProtected,
55-
isBlockProtected,
56-
} from '@/app/workspace/[workspaceId]/w/[workflowId]/utils/block-protection-utils'
5757
import { PreviewWorkflow } from '@/app/workspace/[workspaceId]/w/components/preview'
5858
import { BlockTile } from '@/blocks/block-tile'
5959
import { getBlock } from '@/blocks/registry'
@@ -138,8 +138,10 @@ export function Editor() {
138138
// Check if block is locked (or inside a locked ancestor) and compute edit permission
139139
// Locked blocks cannot be edited by anyone (admins can only lock/unlock)
140140
const blocks = useWorkflowStore((state) => state.blocks)
141-
const isLocked = currentBlockId ? isBlockProtected(currentBlockId, blocks) : false
142-
const isAncestorLocked = currentBlockId ? isAncestorProtected(currentBlockId, blocks) : false
141+
const isLocked = currentBlockId ? isWorkflowBlockProtected(currentBlockId, blocks) : false
142+
const isAncestorLocked = currentBlockId
143+
? isWorkflowBlockAncestorLocked(currentBlockId, blocks)
144+
: false
143145
const canEditBlock = userPermissions.canEdit && !workflowLocked && !isLocked
144146

145147
const { advancedMode, triggerMode } = useEditorBlockProperties(
@@ -332,7 +334,8 @@ export function Editor() {
332334
const block = blocks[blockId]
333335
if (!block) return
334336

335-
if (!userPermissions.canEdit || workflowLocked || isBlockProtected(blockId, blocks)) return
337+
if (!userPermissions.canEdit || workflowLocked || isWorkflowBlockProtected(blockId, blocks))
338+
return
336339

337340
renamingBlockIdRef.current = blockId
338341
setEditedName(block.name || '')

‎apps/sim/app/workspace/[workspaceId]/w/[workflowId]/utils/block-protection-utils.ts‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1+
import { isWorkflowBlockProtected } from '@sim/workflow-types/workflow'
12
import type { BlockState } from '@/stores/workflows/workflow/types'
2-
import { isAncestorProtected, isBlockProtected } from '@/stores/workflows/workflow/utils'
3-
4-
export { isAncestorProtected, isBlockProtected }
53

64
/**
75
* Result of filtering protected blocks from a deletion operation
@@ -28,7 +26,7 @@ export function isEdgeProtected(
2826
edge: { source: string; target: string },
2927
blocks: Record<string, BlockState>
3028
): boolean {
31-
return isBlockProtected(edge.target, blocks)
29+
return isWorkflowBlockProtected(edge.target, blocks)
3230
}
3331

3432
/**
@@ -43,7 +41,7 @@ export function filterProtectedBlocks(
4341
blockIds: string[],
4442
blocks: Record<string, BlockState>
4543
): FilterProtectedBlocksResult {
46-
const protectedIds = blockIds.filter((id) => isBlockProtected(id, blocks))
44+
const protectedIds = blockIds.filter((id) => isWorkflowBlockProtected(id, blocks))
4745
const deletableIds = blockIds.filter((id) => !protectedIds.includes(id))
4846

4947
return {

‎apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use client'
22

33
import React, { lazy, Suspense, useCallback, useEffect, useMemo, useRef, useState } from 'react'
4+
import { isWorkflowBlockProtected } from '@sim/workflow-types/workflow'
45
import {
56
applyNodeChanges,
67
ConnectionLineType,
@@ -102,7 +103,6 @@ import {
102103
getNodeSelectionContextId,
103104
getRunFromBlockDependencyState,
104105
getWorkflowLockToggleIds,
105-
isBlockProtected,
106106
isEdgeProtected,
107107
isInEditableElement,
108108
isPositionalTriggerBlock,
@@ -2890,7 +2890,7 @@ const WorkflowContent = React.memo(
28902890
className: block.data?.parentId ? SUBFLOW_CHILD_NODE_CLASS : undefined,
28912891
extent: block.data?.extent || undefined,
28922892
dragHandle: '.workflow-drag-handle',
2893-
draggable: !workflowReadOnly && !isBlockProtected(block.id, blocks),
2893+
draggable: !workflowReadOnly && !isWorkflowBlockProtected(block.id, blocks),
28942894
zIndex: depth,
28952895
data: {
28962896
...block.data,
@@ -2937,7 +2937,7 @@ const WorkflowContent = React.memo(
29372937
parentId,
29382938
className: parentId ? SUBFLOW_CHILD_NODE_CLASS : undefined,
29392939
dragHandle,
2940-
draggable: !workflowReadOnly && !isBlockProtected(block.id, blocks),
2940+
draggable: !workflowReadOnly && !isWorkflowBlockProtected(block.id, blocks),
29412941
zIndex: cardZIndex,
29422942
extent: (() => {
29432943
// Clamp children to subflow body (exclude header)

‎apps/sim/blocks/icon-color.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
/**
2-
* Contrast helpers for brand tiles. Pure colour maths — deliberately free of any
3-
* `@/blocks/registry` import so the public landing `/integrations` page can use
4-
* these without pulling 282 block configs and the tool registry into its bundle.
5-
* Registry-backed icon styling lives in `@/blocks/brand-icon`.
2+
* Tailwind classes for brand-tile icons, built on the shared
3+
* `isLightTileColor` predicate. Deliberately free of any `@/blocks/registry`
4+
* import so the public landing `/integrations` page can use it without pulling
5+
* every block config and the tool registry into its bundle. Registry-backed
6+
* icon styling lives in `@/blocks/brand-icon`.
67
*/
78
import { isLightTileColor } from '@sim/workflow-renderer/tile-icon-color'
89

‎apps/sim/blocks/pi-api-key-condition.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { resetEnvFlagsMock, setEnvFlags } from '@sim/testing'
22
import { afterAll, afterEach, beforeEach, describe, expect, it } from 'vitest'
33
import { evaluateSubBlockCondition } from '@/lib/workflows/subblocks/visibility'
44
import { PiBlock } from '@/blocks/blocks/pi'
5-
import { getHostedModels } from '@/providers/utils'
5+
import { getHostedModels } from '@/providers/models'
66

77
const apiKeySubBlock = PiBlock.subBlocks.find((subBlock) => subBlock.id === 'apiKey')
88
const hostedModel = getHostedModels()[0]

‎apps/sim/ee/workspace-forking/components/fork-sync-detail-view/fork-sync-detail-view.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ArrowLeft } from '@sim/emcn/icons'
66
import { useQueryState } from 'nuqs'
77
import { saveDiscardActions } from '@/components/settings/save-discard-actions'
88
import type { SettingsAction } from '@/components/settings/settings-header'
9+
import { buildWebhookTriggerUrl } from '@/lib/webhooks/trigger-url'
910
import { UnsavedChangesModal } from '@/app/workspace/[workspaceId]/components/credential-detail'
1011
import {
1112
forkSyncDirectionParam,
@@ -19,7 +20,6 @@ import {
1920
useForkSync,
2021
} from '@/ee/workspace-forking/components/fork-sync/use-fork-sync'
2122
import type { ForkDirection } from '@/ee/workspace-forking/hooks/workspace-fork'
22-
import { buildWebhookTriggerUrl } from '@/triggers/webhook-url'
2323

2424
interface ForkSyncDetailViewProps {
2525
title: string

0 commit comments

Comments
 (0)