Skip to content

Commit 02d4f68

Browse files
committed
Fix rendering of edit subblocks
1 parent b150a41 commit 02d4f68

File tree

2 files changed

+55
-51
lines changed

2 files changed

+55
-51
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/tool-call/tool-call.tsx

Lines changed: 53 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { ClientToolCallState } from '@/lib/copilot/tools/client/base-tool'
88
import { getClientTool } from '@/lib/copilot/tools/client/manager'
99
import { getRegisteredTools } from '@/lib/copilot/tools/client/registry'
1010
import CopilotMarkdownRenderer from '@/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/copilot-message/components/markdown-renderer'
11+
import { getDisplayValue } from '@/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/workflow-block'
1112
import { getBlock } from '@/blocks/registry'
1213
import { CLASS_TOOL_METADATA, useCopilotStore } from '@/stores/panel/copilot/store'
1314
import type { CopilotToolCall, SubAgentContentBlock } from '@/stores/panel/copilot/types'
@@ -954,7 +955,9 @@ function WorkflowEditSummary({ toolCall }: { toolCall: CopilotToolCall }) {
954955
// Group operations by type with block info
955956
interface SubBlockPreview {
956957
id: string
958+
title: string
957959
value: any
960+
isPassword?: boolean
958961
}
959962

960963
interface BlockChange {
@@ -1014,14 +1017,42 @@ function WorkflowEditSummary({ toolCall }: { toolCall: CopilotToolCall }) {
10141017

10151018
const change: BlockChange = { blockId, blockName, blockType }
10161019

1017-
// Extract subblock info from operation params
1020+
// Extract subblock info from operation params, ordered by block config
10181021
if (op.params?.inputs && typeof op.params.inputs === 'object') {
1022+
const inputs = op.params.inputs as Record<string, unknown>
1023+
const blockConfig = getBlock(blockType)
1024+
1025+
// Filter visible subblocks from config (same logic as canvas)
1026+
const visibleSubBlocks =
1027+
blockConfig?.subBlocks?.filter((sb) => {
1028+
// Skip hidden subblocks
1029+
if (sb.hidden) return false
1030+
if (sb.hideFromPreview) return false
1031+
// Skip advanced mode subblocks (not visible by default)
1032+
if (sb.mode === 'advanced') return false
1033+
// Skip trigger mode subblocks
1034+
if (sb.mode === 'trigger') return false
1035+
return true
1036+
}) ?? []
1037+
1038+
// Build subBlocks array respecting config order
10191039
const subBlocks: SubBlockPreview[] = []
1020-
for (const [id, value] of Object.entries(op.params.inputs)) {
1021-
// Skip empty values and connections
1022-
if (value === null || value === undefined || value === '') continue
1023-
subBlocks.push({ id, value })
1040+
1041+
// Add subblocks that are visible in config, in config order
1042+
for (const subBlockConfig of visibleSubBlocks) {
1043+
if (subBlockConfig.id in inputs) {
1044+
const value = inputs[subBlockConfig.id]
1045+
// Skip empty values and connections
1046+
if (value === null || value === undefined || value === '') continue
1047+
subBlocks.push({
1048+
id: subBlockConfig.id,
1049+
title: subBlockConfig.title ?? subBlockConfig.id,
1050+
value,
1051+
isPassword: subBlockConfig.password === true,
1052+
})
1053+
}
10241054
}
1055+
10251056
if (subBlocks.length > 0) {
10261057
if (op.operation_type === 'add') {
10271058
change.subBlocks = subBlocks
@@ -1055,38 +1086,6 @@ function WorkflowEditSummary({ toolCall }: { toolCall: CopilotToolCall }) {
10551086
return getBlock(blockType)
10561087
}
10571088

1058-
// Format subblock value for display
1059-
const formatSubBlockValue = (value: any): string => {
1060-
if (value === null || value === undefined) return ''
1061-
if (typeof value === 'string') {
1062-
// Truncate long strings
1063-
return value.length > 60 ? `${value.slice(0, 60)}...` : value
1064-
}
1065-
if (typeof value === 'boolean') return value ? 'true' : 'false'
1066-
if (typeof value === 'number') return String(value)
1067-
if (Array.isArray(value)) {
1068-
if (value.length === 0) return '[]'
1069-
return `[${value.length} items]`
1070-
}
1071-
if (typeof value === 'object') {
1072-
const keys = Object.keys(value)
1073-
if (keys.length === 0) return '{}'
1074-
return `{${keys.length} fields}`
1075-
}
1076-
return String(value)
1077-
}
1078-
1079-
// Format subblock ID to readable label
1080-
const formatSubBlockLabel = (id: string): string => {
1081-
return id
1082-
.replace(/([A-Z])/g, ' $1')
1083-
.replace(/[_-]/g, ' ')
1084-
.trim()
1085-
.split(' ')
1086-
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
1087-
.join(' ')
1088-
}
1089-
10901089
// Render a single block item with action icon and details
10911090
const renderBlockItem = (change: BlockChange, type: 'add' | 'edit' | 'delete') => {
10921091
const blockConfig = getBlockConfig(change.blockType)
@@ -1128,21 +1127,25 @@ function WorkflowEditSummary({ toolCall }: { toolCall: CopilotToolCall }) {
11281127
<span className={`font-bold font-mono text-[14px] ${color}`}>{symbol}</span>
11291128
</div>
11301129

1131-
{/* Subblock details */}
1130+
{/* Subblock details - uses same title and value formatting as canvas */}
11321131
{subBlocksToShow && subBlocksToShow.length > 0 && (
11331132
<div className='border-[var(--border-1)] border-t bg-[var(--surface-2)] px-2.5 py-1.5'>
1134-
{subBlocksToShow.map((sb) => (
1135-
<div key={sb.id} className='flex items-start gap-1.5 py-0.5 text-[11px]'>
1136-
<span
1137-
className={`font-medium ${type === 'edit' ? 'text-[#f97316]' : 'text-[var(--text-tertiary)]'}`}
1138-
>
1139-
{formatSubBlockLabel(sb.id)}:
1140-
</span>
1141-
<span className='line-clamp-1 break-all text-[var(--text-muted)]'>
1142-
{formatSubBlockValue(sb.value)}
1143-
</span>
1144-
</div>
1145-
))}
1133+
{subBlocksToShow.map((sb) => {
1134+
// Mask password fields like the canvas does
1135+
const displayValue = sb.isPassword ? '•••' : getDisplayValue(sb.value)
1136+
return (
1137+
<div key={sb.id} className='flex items-start gap-1.5 py-0.5 text-[11px]'>
1138+
<span
1139+
className={`font-medium ${type === 'edit' ? 'text-[#f97316]' : 'text-[var(--text-tertiary)]'}`}
1140+
>
1141+
{sb.title}:
1142+
</span>
1143+
<span className='line-clamp-1 break-all text-[var(--text-muted)]'>
1144+
{displayValue}
1145+
</span>
1146+
</div>
1147+
)
1148+
})}
11461149
</div>
11471150
)}
11481151
</div>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,9 @@ const tryParseJson = (value: unknown): unknown => {
199199

200200
/**
201201
* Formats a subblock value for display, intelligently handling nested objects and arrays.
202+
* Used by both the canvas workflow blocks and copilot edit summaries.
202203
*/
203-
const getDisplayValue = (value: unknown): string => {
204+
export const getDisplayValue = (value: unknown): string => {
204205
if (value == null || value === '') return '-'
205206

206207
// Try parsing JSON strings first

0 commit comments

Comments
 (0)