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
57 changes: 6 additions & 51 deletions apps/sim/lib/workflows/comparison/resolve-values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,56 +40,8 @@ interface ResolutionContext {
blockId?: string
}

function getSemanticFallback(subBlockId: string, subBlockConfig?: SubBlockConfig): string {
if (subBlockConfig?.title) {
return subBlockConfig.title.toLowerCase()
}

const patterns: Record<string, string> = {
credential: 'credential',
channel: 'channel',
channelId: 'channel',
user: 'user',
userId: 'user',
workflow: 'workflow',
workflowId: 'workflow',
file: 'file',
fileId: 'file',
folder: 'folder',
folderId: 'folder',
project: 'project',
projectId: 'project',
team: 'team',
teamId: 'team',
sheet: 'sheet',
sheetId: 'sheet',
document: 'document',
documentId: 'document',
knowledgeBase: 'knowledge base',
knowledgeBaseId: 'knowledge base',
server: 'server',
serverId: 'server',
tool: 'tool',
toolId: 'tool',
calendar: 'calendar',
calendarId: 'calendar',
label: 'label',
labelId: 'label',
site: 'site',
siteId: 'site',
collection: 'collection',
collectionId: 'collection',
item: 'item',
itemId: 'item',
contact: 'contact',
contactId: 'contact',
task: 'task',
taskId: 'task',
chat: 'chat',
chatId: 'chat',
}

return patterns[subBlockId] || 'value'
function getSemanticFallback(subBlockConfig: SubBlockConfig): string {
return (subBlockConfig.title ?? subBlockConfig.id).toLowerCase()
}

async function resolveCredential(credentialId: string, workflowId: string): Promise<string | null> {
Expand Down Expand Up @@ -219,7 +171,10 @@ export async function resolveValueForDisplay(

const blockConfig = getBlock(context.blockType)
const subBlockConfig = blockConfig?.subBlocks.find((sb) => sb.id === context.subBlockId)
const semanticFallback = getSemanticFallback(context.subBlockId, subBlockConfig)
if (!subBlockConfig) {
return { original: value, displayLabel: formatValueForDisplay(value), resolved: false }
}
const semanticFallback = getSemanticFallback(subBlockConfig)

const selectorCtx = context.blockId
? extractSelectorContext(context.blockId, context.currentState, context.workflowId)
Expand Down
15 changes: 11 additions & 4 deletions apps/sim/lib/workflows/persistence/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ export async function loadDeployedWorkflowState(
resolvedWorkspaceId = wfRow?.workspaceId ?? undefined
}

if (!resolvedWorkspaceId) {
throw new Error(`Workflow ${workflowId} has no workspace`)
}

const { blocks: migratedBlocks } = await applyBlockMigrations(
state.blocks || {},
resolvedWorkspaceId
Expand All @@ -139,7 +143,7 @@ export async function loadDeployedWorkflowState(

interface MigrationContext {
blocks: Record<string, BlockState>
workspaceId?: string
workspaceId: string
migrated: boolean
}

Expand All @@ -148,7 +152,7 @@ type BlockMigration = (ctx: MigrationContext) => MigrationContext | Promise<Migr
function createMigrationPipeline(migrations: BlockMigration[]) {
return async (
blocks: Record<string, BlockState>,
workspaceId?: string
workspaceId: string
): Promise<{ blocks: Record<string, BlockState>; migrated: boolean }> => {
let ctx: MigrationContext = { blocks, workspaceId, migrated: false }
for (const migration of migrations) {
Expand All @@ -170,7 +174,6 @@ const applyBlockMigrations = createMigrationPipeline([
}),

async (ctx) => {
if (!ctx.workspaceId) return ctx
const { blocks, migrated } = await migrateCredentialIds(ctx.blocks, ctx.workspaceId)
return { ...ctx, blocks, migrated: ctx.migrated || migrated }
},
Expand Down Expand Up @@ -409,9 +412,13 @@ export async function loadWorkflowFromNormalizedTables(
blocksMap[block.id] = assembled
})

if (!workflowRow?.workspaceId) {
throw new Error(`Workflow ${workflowId} has no workspace`)
}

const { blocks: finalBlocks, migrated } = await applyBlockMigrations(
blocksMap,
workflowRow?.workspaceId ?? undefined
workflowRow.workspaceId
)

if (migrated) {
Expand Down