Skip to content

Commit 6b42434

Browse files
committed
cleanup code
1 parent d099be4 commit 6b42434

File tree

6 files changed

+340
-157
lines changed

6 files changed

+340
-157
lines changed

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

Lines changed: 82 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
Code,
3636
FileSelectorInput,
3737
FileUpload,
38+
FolderSelectorInput,
3839
LongInput,
3940
ProjectSelectorInput,
4041
SheetSelectorInput,
@@ -313,6 +314,42 @@ function SheetSelectorSyncWrapper({
313314
)
314315
}
315316

317+
function FolderSelectorSyncWrapper({
318+
blockId,
319+
paramId,
320+
value,
321+
onChange,
322+
uiComponent,
323+
disabled,
324+
previewContextValues,
325+
}: {
326+
blockId: string
327+
paramId: string
328+
value: string
329+
onChange: (value: string) => void
330+
uiComponent: any
331+
disabled: boolean
332+
previewContextValues?: Record<string, any>
333+
}) {
334+
return (
335+
<GenericSyncWrapper blockId={blockId} paramId={paramId} value={value} onChange={onChange}>
336+
<FolderSelectorInput
337+
blockId={blockId}
338+
subBlock={{
339+
id: paramId,
340+
type: 'folder-selector' as const,
341+
title: paramId,
342+
serviceId: uiComponent.serviceId,
343+
requiredScopes: uiComponent.requiredScopes || [],
344+
placeholder: uiComponent.placeholder,
345+
dependsOn: uiComponent.dependsOn,
346+
}}
347+
disabled={disabled}
348+
/>
349+
</GenericSyncWrapper>
350+
)
351+
}
352+
316353
function KnowledgeBaseSelectorSyncWrapper({
317354
blockId,
318355
paramId,
@@ -569,11 +606,15 @@ function CheckboxListSyncWrapper({
569606
}
570607

571608
function ComboboxSyncWrapper({
609+
blockId,
610+
paramId,
572611
value,
573612
onChange,
574613
uiComponent,
575614
disabled,
576615
}: {
616+
blockId: string
617+
paramId: string
577618
value: string
578619
onChange: (value: string) => void
579620
uiComponent: any
@@ -584,13 +625,15 @@ function ComboboxSyncWrapper({
584625
)
585626

586627
return (
587-
<Combobox
588-
options={options}
589-
value={value}
590-
onChange={onChange}
591-
placeholder={uiComponent.placeholder || 'Select option'}
592-
disabled={disabled}
593-
/>
628+
<GenericSyncWrapper blockId={blockId} paramId={paramId} value={value} onChange={onChange}>
629+
<Combobox
630+
options={options}
631+
value={value}
632+
onChange={onChange}
633+
placeholder={uiComponent.placeholder || 'Select option'}
634+
disabled={disabled}
635+
/>
636+
</GenericSyncWrapper>
594637
)
595638
}
596639

@@ -669,13 +712,17 @@ function SlackSelectorSyncWrapper({
669712
}
670713

671714
function WorkflowSelectorSyncWrapper({
715+
blockId,
716+
paramId,
672717
value,
673718
onChange,
674719
uiComponent,
675720
disabled,
676721
workspaceId,
677722
currentWorkflowId,
678723
}: {
724+
blockId: string
725+
paramId: string
679726
value: string
680727
onChange: (value: string) => void
681728
uiComponent: any
@@ -695,15 +742,17 @@ function WorkflowSelectorSyncWrapper({
695742
}))
696743

697744
return (
698-
<Combobox
699-
options={options}
700-
value={value}
701-
onChange={onChange}
702-
placeholder={uiComponent.placeholder || 'Select workflow'}
703-
disabled={disabled || isLoading}
704-
searchable
705-
searchPlaceholder='Search workflows...'
706-
/>
745+
<GenericSyncWrapper blockId={blockId} paramId={paramId} value={value} onChange={onChange}>
746+
<Combobox
747+
options={options}
748+
value={value}
749+
onChange={onChange}
750+
placeholder={uiComponent.placeholder || 'Select workflow'}
751+
disabled={disabled || isLoading}
752+
searchable
753+
searchPlaceholder='Search workflows...'
754+
/>
755+
</GenericSyncWrapper>
707756
)
708757
}
709758

@@ -2065,6 +2114,19 @@ export function ToolInput({
20652114
/>
20662115
)
20672116

2117+
case 'folder-selector':
2118+
return (
2119+
<FolderSelectorSyncWrapper
2120+
blockId={blockId}
2121+
paramId={param.id}
2122+
value={value}
2123+
onChange={onChange}
2124+
uiComponent={uiComponent}
2125+
disabled={disabled}
2126+
previewContextValues={currentToolParams}
2127+
/>
2128+
)
2129+
20682130
case 'table':
20692131
return (
20702132
<TableSyncWrapper
@@ -2080,6 +2142,8 @@ export function ToolInput({
20802142
case 'combobox':
20812143
return (
20822144
<ComboboxSyncWrapper
2145+
blockId={blockId}
2146+
paramId={param.id}
20832147
value={value}
20842148
onChange={onChange}
20852149
uiComponent={uiComponent}
@@ -2138,6 +2202,8 @@ export function ToolInput({
21382202
case 'workflow-selector':
21392203
return (
21402204
<WorkflowSelectorSyncWrapper
2205+
blockId={blockId}
2206+
paramId={param.id}
21412207
value={value}
21422208
onChange={onChange}
21432209
uiComponent={uiComponent}

apps/sim/providers/utils.ts

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030
import type { ProviderId, ProviderToolConfig } from '@/providers/types'
3131
import { useCustomToolsStore } from '@/stores/custom-tools/store'
3232
import { useProvidersStore } from '@/stores/providers/store'
33-
import { deepMergeInputMapping, isEmptyTagValue } from '@/tools/params'
33+
import { mergeToolParameters } from '@/tools/params'
3434

3535
const logger = createLogger('ProviderUtils')
3636

@@ -986,38 +986,8 @@ export function prepareToolExecution(
986986
toolParams: Record<string, any>
987987
executionParams: Record<string, any>
988988
} {
989-
const filteredUserParams: Record<string, any> = {}
990-
if (tool.params) {
991-
for (const [key, value] of Object.entries(tool.params)) {
992-
if (value !== undefined && value !== null && value !== '') {
993-
// Skip tag-based params if they're effectively empty (only default/unfilled entries)
994-
if ((key === 'documentTags' || key === 'tagFilters') && isEmptyTagValue(value)) {
995-
continue
996-
}
997-
filteredUserParams[key] = value
998-
}
999-
}
1000-
}
1001-
1002-
// Start with LLM params as base
1003-
const toolParams: Record<string, any> = { ...llmArgs }
1004-
1005-
// Apply user params with special handling for inputMapping
1006-
for (const [key, userValue] of Object.entries(filteredUserParams)) {
1007-
if (key === 'inputMapping') {
1008-
// Deep merge inputMapping so LLM values fill in empty user fields
1009-
const llmInputMapping = llmArgs.inputMapping as Record<string, any> | undefined
1010-
toolParams.inputMapping = deepMergeInputMapping(llmInputMapping, userValue)
1011-
} else {
1012-
// Normal override for other params
1013-
toolParams[key] = userValue
1014-
}
1015-
}
1016-
1017-
// If LLM provided inputMapping but user didn't, ensure it's included
1018-
if (llmArgs.inputMapping && !filteredUserParams.inputMapping) {
1019-
toolParams.inputMapping = llmArgs.inputMapping
1020-
}
989+
// Use centralized merge logic from tools/params
990+
const toolParams = mergeToolParameters(tool.params || {}, llmArgs) as Record<string, any>
1021991

1022992
const executionParams = {
1023993
...toolParams,

apps/sim/tools/knowledge/create_document.ts

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { KnowledgeCreateDocumentResponse } from '@/tools/knowledge/types'
22
import { enrichKBTagsSchema } from '@/tools/schema-enrichers'
3+
import { formatDocumentTagsForAPI, parseDocumentTags } from '@/tools/tag-utils'
34
import type { ToolConfig } from '@/tools/types'
45

56
export const knowledgeCreateDocumentTool: ToolConfig<any, KnowledgeCreateDocumentResponse> = {
@@ -76,42 +77,9 @@ export const knowledgeCreateDocumentTool: ToolConfig<any, KnowledgeCreateDocumen
7677

7778
const dataUri = `data:text/plain;base64,${base64Content}`
7879

79-
const tagData: Record<string, string> = {}
80-
81-
if (params.documentTags) {
82-
let tagsArray: Array<{ tagName: string; value: string }> = []
83-
84-
// Handle object format from LLM: { "Category": "foo", "Priority": 5 }
85-
if (
86-
typeof params.documentTags === 'object' &&
87-
!Array.isArray(params.documentTags) &&
88-
params.documentTags !== null
89-
) {
90-
tagsArray = Object.entries(params.documentTags).map(([tagName, value]) => ({
91-
tagName,
92-
value: String(value),
93-
}))
94-
}
95-
// Handle string (JSON) format from standalone block
96-
else if (typeof params.documentTags === 'string') {
97-
try {
98-
const parsed = JSON.parse(params.documentTags)
99-
if (Array.isArray(parsed)) {
100-
tagsArray = parsed
101-
}
102-
} catch {
103-
// Ignore parse errors
104-
}
105-
}
106-
// Handle array format directly
107-
else if (Array.isArray(params.documentTags)) {
108-
tagsArray = params.documentTags
109-
}
110-
111-
if (tagsArray.length > 0) {
112-
tagData.documentTagsData = JSON.stringify(tagsArray)
113-
}
114-
}
80+
// Parse document tags from various formats (object, array, JSON string)
81+
const parsedTags = parseDocumentTags(params.documentTags)
82+
const tagData = formatDocumentTagsForAPI(parsedTags)
11583

11684
const documents = [
11785
{

apps/sim/tools/knowledge/search.ts

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { StructuredFilter } from '@/lib/knowledge/types'
21
import type { KnowledgeSearchResponse } from '@/tools/knowledge/types'
32
import { enrichKBTagFiltersSchema } from '@/tools/schema-enrichers'
3+
import { parseTagFilters } from '@/tools/tag-utils'
44
import type { ToolConfig } from '@/tools/types'
55

66
export const knowledgeSearchTool: ToolConfig<any, KnowledgeSearchResponse> = {
@@ -62,40 +62,8 @@ export const knowledgeSearchTool: ToolConfig<any, KnowledgeSearchResponse> = {
6262
// Use single knowledge base ID
6363
const knowledgeBaseIds = [params.knowledgeBaseId]
6464

65-
// Parse dynamic tag filters
66-
let structuredFilters: StructuredFilter[] = []
67-
if (params.tagFilters) {
68-
let tagFilters = params.tagFilters
69-
70-
// Handle both string (JSON) and array formats
71-
if (typeof tagFilters === 'string') {
72-
try {
73-
tagFilters = JSON.parse(tagFilters)
74-
} catch {
75-
tagFilters = []
76-
}
77-
}
78-
79-
if (Array.isArray(tagFilters)) {
80-
// Send full filter objects with operator support
81-
structuredFilters = tagFilters
82-
.filter((filter: Record<string, unknown>) => {
83-
// For boolean, any value is valid; for others, check for non-empty string
84-
if (filter.fieldType === 'boolean') {
85-
return filter.tagName && filter.tagValue !== undefined
86-
}
87-
return filter.tagName && filter.tagValue && String(filter.tagValue).trim().length > 0
88-
})
89-
.map((filter: Record<string, unknown>) => ({
90-
tagName: filter.tagName as string,
91-
tagSlot: (filter.tagSlot as string) || '', // Will be resolved by API from tagName
92-
fieldType: (filter.fieldType as string) || 'text',
93-
operator: (filter.operator as string) || 'eq',
94-
value: filter.tagValue as string | number | boolean,
95-
valueTo: filter.valueTo as string | number | undefined,
96-
}))
97-
}
98-
}
65+
// Parse tag filters from various formats (array, JSON string)
66+
const structuredFilters = parseTagFilters(params.tagFilters)
9967

10068
const requestBody = {
10169
knowledgeBaseIds,

0 commit comments

Comments
 (0)