Skip to content

Commit f4e627a

Browse files
icecrasher321Vikhyath MondretiVikhyath MondretiVikhyath Mondretigreptile-apps[bot]
authored
v0.2.3: fix (#592)
* fix(variable resolution): use variable references to not have escaping issues (#587) * fix(variable-resolution): don't inject stringified json, use var refs * fix lint * remove unused var --------- Co-authored-by: Vikhyath Mondreti <[email protected]> * fix(subblock updates): special selectors persistence (#591) * fix(knowledge-base-selector): should trigger sockets event for persistence * fix subblock value updates for non useSubblockValue components * fix lint --------- Co-authored-by: Vikhyath Mondreti <[email protected]> * fix(race-cond): for auto-connect rare race condition between adding edge + block (#582) * auto connect race condition * fix lint * Update apps/sim/hooks/use-collaborative-workflow.ts Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> * Update apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> * fix lint --------- Co-authored-by: Vikhyath Mondreti <[email protected]> Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> Co-authored-by: Vikhyath Mondreti <[email protected]> --------- Co-authored-by: Vikhyath Mondreti <[email protected]> Co-authored-by: Vikhyath Mondreti <[email protected]> Co-authored-by: Vikhyath Mondreti <[email protected]> Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
1 parent b0c1547 commit f4e627a

File tree

11 files changed

+205
-78
lines changed

11 files changed

+205
-78
lines changed

apps/sim/app/api/function/execute/route.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,12 @@ function resolveCodeVariables(
5858

5959
// Find the block ID by looking for a block name that normalizes to this value
6060
let blockId = null
61-
let matchedBlockName = null
6261

6362
for (const [blockName, id] of Object.entries(blockNameMapping)) {
6463
// Apply the same normalization logic as the UI: remove spaces and lowercase
6564
const normalizedName = blockName.replace(/\s+/g, '').toLowerCase()
6665
if (normalizedName === normalizedBlockName) {
6766
blockId = id
68-
matchedBlockName = blockName
6967
break
7068
}
7169
}
@@ -151,9 +149,6 @@ export async function POST(req: NextRequest) {
151149
})
152150

153151
// Resolve variables in the code with workflow environment variables
154-
logger.info(`[${requestId}] Original code:`, code.substring(0, 200))
155-
logger.info(`[${requestId}] Execution params keys:`, Object.keys(executionParams))
156-
157152
const { resolvedCode, contextVariables } = resolveCodeVariables(
158153
code,
159154
executionParams,
@@ -162,9 +157,6 @@ export async function POST(req: NextRequest) {
162157
blockNameMapping
163158
)
164159

165-
logger.info(`[${requestId}] Resolved code:`, resolvedCode.substring(0, 200))
166-
logger.info(`[${requestId}] Context variables keys:`, Object.keys(contextVariables))
167-
168160
const executionMethod = 'vm' // Default execution method
169161

170162
// // Try to use Freestyle if the API key is available

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
} from '@/components/ui/command'
1414
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
1515
import type { SubBlockConfig } from '@/blocks/types'
16+
import { useCollaborativeWorkflow } from '@/hooks/use-collaborative-workflow'
1617
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
1718

1819
interface DocumentData {
@@ -50,7 +51,8 @@ export function DocumentSelector({
5051
isPreview = false,
5152
previewValue,
5253
}: DocumentSelectorProps) {
53-
const { getValue, setValue } = useSubBlockStore()
54+
const { getValue } = useSubBlockStore()
55+
const { collaborativeSetSubblockValue } = useCollaborativeWorkflow()
5456

5557
const [documents, setDocuments] = useState<DocumentData[]>([])
5658
const [error, setError] = useState<string | null>(null)
@@ -117,7 +119,7 @@ export function DocumentSelector({
117119
if (selectedId && !fetchedDocuments.some((doc: DocumentData) => doc.id === selectedId)) {
118120
setSelectedId('')
119121
if (!isPreview) {
120-
setValue(blockId, subBlock.id, '')
122+
collaborativeSetSubblockValue(blockId, subBlock.id, '')
121123
}
122124
}
123125

@@ -131,7 +133,7 @@ export function DocumentSelector({
131133
setSelectedId(singleDoc.id)
132134
setSelectedDocument(singleDoc)
133135
if (!isPreview) {
134-
setValue(blockId, subBlock.id, singleDoc.id)
136+
collaborativeSetSubblockValue(blockId, subBlock.id, singleDoc.id)
135137
}
136138
onDocumentSelect?.(singleDoc.id)
137139
}
@@ -141,7 +143,15 @@ export function DocumentSelector({
141143
setError((err as Error).message)
142144
setDocuments([])
143145
}
144-
}, [knowledgeBaseId, selectedId, setValue, blockId, subBlock.id, isPreview, onDocumentSelect])
146+
}, [
147+
knowledgeBaseId,
148+
selectedId,
149+
collaborativeSetSubblockValue,
150+
blockId,
151+
subBlock.id,
152+
isPreview,
153+
onDocumentSelect,
154+
])
145155

146156
// Handle dropdown open/close - fetch documents when opening
147157
const handleOpenChange = (isOpen: boolean) => {
@@ -163,7 +173,7 @@ export function DocumentSelector({
163173
setSelectedId(document.id)
164174

165175
if (!isPreview) {
166-
setValue(blockId, subBlock.id, document.id)
176+
collaborativeSetSubblockValue(blockId, subBlock.id, document.id)
167177
}
168178

169179
onDocumentSelect?.(document.id)
@@ -193,10 +203,10 @@ export function DocumentSelector({
193203
setInitialFetchDone(false)
194204
setError(null)
195205
if (!isPreview) {
196-
setValue(blockId, subBlock.id, '')
206+
collaborativeSetSubblockValue(blockId, subBlock.id, '')
197207
}
198208
}
199-
}, [knowledgeBaseId, blockId, subBlock.id, setValue, isPreview])
209+
}, [knowledgeBaseId, blockId, subBlock.id, collaborativeSetSubblockValue, isPreview])
200210

201211
// Fetch documents when knowledge base is available and we haven't fetched yet
202212
useEffect(() => {

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useEffect, useState } from 'react'
44
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'
55
import { env } from '@/lib/env'
66
import type { SubBlockConfig } from '@/blocks/types'
7+
import { useCollaborativeWorkflow } from '@/hooks/use-collaborative-workflow'
78
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
89
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
910
import type { ConfluenceFileInfo } from './components/confluence-file-selector'
@@ -36,7 +37,8 @@ export function FileSelectorInput({
3637
isPreview = false,
3738
previewValue,
3839
}: FileSelectorInputProps) {
39-
const { getValue, setValue } = useSubBlockStore()
40+
const { getValue } = useSubBlockStore()
41+
const { collaborativeSetSubblockValue } = useCollaborativeWorkflow()
4042
const { activeWorkflowId } = useWorkflowRegistry()
4143
const [selectedFileId, setSelectedFileId] = useState<string>('')
4244
const [_fileInfo, setFileInfo] = useState<FileInfo | ConfluenceFileInfo | null>(null)
@@ -115,34 +117,34 @@ export function FileSelectorInput({
115117
const handleFileChange = (fileId: string, info?: any) => {
116118
setSelectedFileId(fileId)
117119
setFileInfo(info || null)
118-
setValue(blockId, subBlock.id, fileId)
120+
collaborativeSetSubblockValue(blockId, subBlock.id, fileId)
119121
}
120122

121123
// Handle issue selection
122124
const handleIssueChange = (issueKey: string, info?: JiraIssueInfo) => {
123125
setSelectedIssueId(issueKey)
124126
setIssueInfo(info || null)
125-
setValue(blockId, subBlock.id, issueKey)
127+
collaborativeSetSubblockValue(blockId, subBlock.id, issueKey)
126128

127129
// Clear the fields when a new issue is selected
128130
if (isJira) {
129-
setValue(blockId, 'summary', '')
130-
setValue(blockId, 'description', '')
131+
collaborativeSetSubblockValue(blockId, 'summary', '')
132+
collaborativeSetSubblockValue(blockId, 'description', '')
131133
}
132134
}
133135

134136
// Handle channel selection
135137
const handleChannelChange = (channelId: string, info?: DiscordChannelInfo) => {
136138
setSelectedChannelId(channelId)
137139
setChannelInfo(info || null)
138-
setValue(blockId, subBlock.id, channelId)
140+
collaborativeSetSubblockValue(blockId, subBlock.id, channelId)
139141
}
140142

141143
// Handle calendar selection
142144
const handleCalendarChange = (calendarId: string, info?: GoogleCalendarInfo) => {
143145
setSelectedCalendarId(calendarId)
144146
setCalendarInfo(info || null)
145-
setValue(blockId, subBlock.id, calendarId)
147+
collaborativeSetSubblockValue(blockId, subBlock.id, calendarId)
146148
}
147149

148150
// For Google Drive
@@ -337,7 +339,7 @@ export function FileSelectorInput({
337339
onChange={(value, info) => {
338340
setSelectedMessageId(value)
339341
setMessageInfo(info || null)
340-
setValue(blockId, subBlock.id, value)
342+
collaborativeSetSubblockValue(blockId, subBlock.id, value)
341343
}}
342344
provider='microsoft-teams'
343345
requiredScopes={subBlock.requiredScopes || []}

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

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { useRef, useState } from 'react'
44
import { X } from 'lucide-react'
55
import { Button } from '@/components/ui/button'
66
import { Progress } from '@/components/ui/progress'
7+
import { useCollaborativeWorkflow } from '@/hooks/use-collaborative-workflow'
78
import { useNotificationStore } from '@/stores/notifications/store'
89
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
9-
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
1010
import { useWorkflowStore } from '@/stores/workflows/workflow/store'
1111
import { useSubBlockValue } from '../hooks/use-sub-block-value'
1212

@@ -58,6 +58,7 @@ export function FileUpload({
5858
// Stores
5959
const { addNotification } = useNotificationStore()
6060
const { activeWorkflowId } = useWorkflowRegistry()
61+
const { collaborativeSetSubblockValue } = useCollaborativeWorkflow()
6162

6263
// Use preview value when in preview mode, otherwise use store value
6364
const value = isPreview ? previewValue : storeValue
@@ -298,15 +299,15 @@ export function FileUpload({
298299

299300
setStoreValue(newFiles)
300301

301-
// Make sure to update the subblock store value for the workflow execution
302-
useSubBlockStore.getState().setValue(blockId, subBlockId, newFiles)
302+
// Use collaborative update for persistence
303+
collaborativeSetSubblockValue(blockId, subBlockId, newFiles)
303304
useWorkflowStore.getState().triggerUpdate()
304305
} else {
305306
// For single file: Replace with last uploaded file
306307
setStoreValue(uploadedFiles[0] || null)
307308

308-
// Make sure to update the subblock store value for the workflow execution
309-
useSubBlockStore.getState().setValue(blockId, subBlockId, uploadedFiles[0] || null)
309+
// Use collaborative update for persistence
310+
collaborativeSetSubblockValue(blockId, subBlockId, uploadedFiles[0] || null)
310311
useWorkflowStore.getState().triggerUpdate()
311312
}
312313
} catch (error) {
@@ -363,16 +364,18 @@ export function FileUpload({
363364
const updatedFiles = filesArray.filter((f) => f.path !== file.path)
364365
setStoreValue(updatedFiles.length > 0 ? updatedFiles : null)
365366

366-
// Make sure to update the subblock store value for the workflow execution
367-
useSubBlockStore
368-
.getState()
369-
.setValue(blockId, subBlockId, updatedFiles.length > 0 ? updatedFiles : null)
367+
// Use collaborative update for persistence
368+
collaborativeSetSubblockValue(
369+
blockId,
370+
subBlockId,
371+
updatedFiles.length > 0 ? updatedFiles : null
372+
)
370373
} else {
371374
// For single file: Clear the value
372375
setStoreValue(null)
373376

374-
// Make sure to update the subblock store
375-
useSubBlockStore.getState().setValue(blockId, subBlockId, null)
377+
// Use collaborative update for persistence
378+
collaborativeSetSubblockValue(blockId, subBlockId, null)
376379
}
377380

378381
useWorkflowStore.getState().triggerUpdate()
@@ -413,7 +416,7 @@ export function FileUpload({
413416

414417
// Clear input state immediately for better UX
415418
setStoreValue(null)
416-
useSubBlockStore.getState().setValue(blockId, subBlockId, null)
419+
collaborativeSetSubblockValue(blockId, subBlockId, null)
417420
useWorkflowStore.getState().triggerUpdate()
418421

419422
if (fileInputRef.current) {

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
} from '@/components/ui/command'
1515
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
1616
import type { SubBlockConfig } from '@/blocks/types'
17+
import { useCollaborativeWorkflow } from '@/hooks/use-collaborative-workflow'
1718
import { type KnowledgeBaseData, useKnowledgeStore } from '@/stores/knowledge/store'
1819
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
1920

@@ -36,7 +37,8 @@ export function KnowledgeBaseSelector({
3637
}: KnowledgeBaseSelectorProps) {
3738
const { getKnowledgeBasesList, knowledgeBasesList, loadingKnowledgeBasesList } =
3839
useKnowledgeStore()
39-
const { getValue, setValue } = useSubBlockStore()
40+
const { getValue } = useSubBlockStore()
41+
const { collaborativeSetSubblockValue } = useCollaborativeWorkflow()
4042

4143
const [knowledgeBases, setKnowledgeBases] = useState<KnowledgeBaseData[]>([])
4244
const [loading, setLoading] = useState(false)
@@ -90,7 +92,8 @@ export function KnowledgeBaseSelector({
9092
setSelectedKnowledgeBases([knowledgeBase])
9193

9294
if (!isPreview) {
93-
setValue(blockId, subBlock.id, knowledgeBase.id)
95+
// Use collaborative update for both local store and persistence
96+
collaborativeSetSubblockValue(blockId, subBlock.id, knowledgeBase.id)
9497
}
9598

9699
onKnowledgeBaseSelect?.(knowledgeBase.id)
@@ -117,7 +120,8 @@ export function KnowledgeBaseSelector({
117120
if (!isPreview) {
118121
const selectedIds = newSelected.map((kb) => kb.id)
119122
const valueToStore = selectedIds.length === 1 ? selectedIds[0] : selectedIds.join(',')
120-
setValue(blockId, subBlock.id, valueToStore)
123+
// Use collaborative update for both local store and persistence
124+
collaborativeSetSubblockValue(blockId, subBlock.id, valueToStore)
121125
}
122126

123127
onKnowledgeBaseSelect?.(newSelected.map((kb) => kb.id))
@@ -133,7 +137,8 @@ export function KnowledgeBaseSelector({
133137
if (!isPreview) {
134138
const selectedIds = newSelected.map((kb) => kb.id)
135139
const valueToStore = selectedIds.length === 1 ? selectedIds[0] : selectedIds.join(',')
136-
setValue(blockId, subBlock.id, valueToStore)
140+
// Use collaborative update for both local store and persistence
141+
collaborativeSetSubblockValue(blockId, subBlock.id, valueToStore)
137142
}
138143

139144
onKnowledgeBaseSelect?.(newSelected.map((kb) => kb.id))

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { useEffect, useState } from 'react'
44
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'
55
import type { SubBlockConfig } from '@/blocks/types'
6+
import { useCollaborativeWorkflow } from '@/hooks/use-collaborative-workflow'
67
import { useSubBlockStore } from '@/stores/workflows/subblock/store'
78
import { type DiscordServerInfo, DiscordServerSelector } from './components/discord-server-selector'
89
import { type JiraProjectInfo, JiraProjectSelector } from './components/jira-project-selector'
@@ -26,7 +27,8 @@ export function ProjectSelectorInput({
2627
isPreview = false,
2728
previewValue,
2829
}: ProjectSelectorInputProps) {
29-
const { getValue, setValue } = useSubBlockStore()
30+
const { getValue } = useSubBlockStore()
31+
const { collaborativeSetSubblockValue } = useCollaborativeWorkflow()
3032
const [selectedProjectId, setSelectedProjectId] = useState<string>('')
3133
const [_projectInfo, setProjectInfo] = useState<JiraProjectInfo | DiscordServerInfo | null>(null)
3234

@@ -58,21 +60,21 @@ export function ProjectSelectorInput({
5860
) => {
5961
setSelectedProjectId(projectId)
6062
setProjectInfo(info || null)
61-
setValue(blockId, subBlock.id, projectId)
63+
collaborativeSetSubblockValue(blockId, subBlock.id, projectId)
6264

6365
// Clear the issue-related fields when a new project is selected
6466
if (provider === 'jira') {
65-
setValue(blockId, 'summary', '')
66-
setValue(blockId, 'description', '')
67-
setValue(blockId, 'issueKey', '')
67+
collaborativeSetSubblockValue(blockId, 'summary', '')
68+
collaborativeSetSubblockValue(blockId, 'description', '')
69+
collaborativeSetSubblockValue(blockId, 'issueKey', '')
6870
} else if (provider === 'discord') {
69-
setValue(blockId, 'channelId', '')
71+
collaborativeSetSubblockValue(blockId, 'channelId', '')
7072
} else if (provider === 'linear') {
7173
if (subBlock.id === 'teamId') {
72-
setValue(blockId, 'teamId', projectId)
73-
setValue(blockId, 'projectId', '')
74+
collaborativeSetSubblockValue(blockId, 'teamId', projectId)
75+
collaborativeSetSubblockValue(blockId, 'projectId', '')
7476
} else if (subBlock.id === 'projectId') {
75-
setValue(blockId, 'projectId', projectId)
77+
collaborativeSetSubblockValue(blockId, 'projectId', projectId)
7678
}
7779
}
7880

0 commit comments

Comments
 (0)