diff --git a/apps/sim/lib/workflows/comparison/resolve-values.ts b/apps/sim/lib/workflows/comparison/resolve-values.ts index 1eb31d97ea..cd675824b1 100644 --- a/apps/sim/lib/workflows/comparison/resolve-values.ts +++ b/apps/sim/lib/workflows/comparison/resolve-values.ts @@ -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 = { - 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 { @@ -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) diff --git a/apps/sim/lib/workflows/persistence/utils.ts b/apps/sim/lib/workflows/persistence/utils.ts index fa6a9bb517..89b7b7f602 100644 --- a/apps/sim/lib/workflows/persistence/utils.ts +++ b/apps/sim/lib/workflows/persistence/utils.ts @@ -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 @@ -139,7 +143,7 @@ export async function loadDeployedWorkflowState( interface MigrationContext { blocks: Record - workspaceId?: string + workspaceId: string migrated: boolean } @@ -148,7 +152,7 @@ type BlockMigration = (ctx: MigrationContext) => MigrationContext | Promise, - workspaceId?: string + workspaceId: string ): Promise<{ blocks: Record; migrated: boolean }> => { let ctx: MigrationContext = { blocks, workspaceId, migrated: false } for (const migration of migrations) { @@ -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 } }, @@ -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) {