Skip to content

Commit 7377a10

Browse files
authored
fix(custom-tool): include schema parameters in code wand prompt (#4360)
1 parent 07e7670 commit 7377a10

1 file changed

Lines changed: 32 additions & 18 deletions

File tree

  • apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/editor/components/sub-block/components/tool-input/components/custom-tool-modal

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

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,36 @@ Example 2:
191191
},
192192
})
193193

194+
const schemaParameters = useMemo(() => {
195+
try {
196+
if (!jsonSchema) return []
197+
const parsed = JSON.parse(jsonSchema)
198+
const properties = parsed?.function?.parameters?.properties
199+
if (!properties) return []
200+
201+
return Object.keys(properties).map((key) => ({
202+
name: key,
203+
type: properties[key].type || 'any',
204+
description: properties[key].description || '',
205+
required: parsed?.function?.parameters?.required?.includes(key) || false,
206+
}))
207+
} catch {
208+
return []
209+
}
210+
}, [jsonSchema])
211+
212+
const codeGenerationSchemaContext = useMemo(() => {
213+
if (schemaParameters.length === 0) {
214+
return 'Schema parameters: (none defined yet — the user has not added any parameters to the schema)'
215+
}
216+
const lines = schemaParameters.map((p) => {
217+
const requiredLabel = p.required ? 'required' : 'optional'
218+
const description = p.description ? `: ${p.description}` : ''
219+
return `- ${p.name} (${p.type}, ${requiredLabel})${description}`
220+
})
221+
return `Schema parameters (reference these directly by name in the generated code):\n${lines.join('\n')}`
222+
}, [schemaParameters])
223+
194224
const codeGeneration = useWand({
195225
wandConfig: {
196226
enabled: true,
@@ -201,6 +231,8 @@ The code should be executable within an 'async function(params, environmentVaria
201231
- 'params' (object): Contains input parameters derived from the JSON schema. Reference these directly by name (e.g., 'userId', 'cityName'). Do NOT use 'params.paramName'.
202232
- 'environmentVariables' (object): Contains environment variables. Reference these using the double curly brace syntax: '{{ENV_VAR_NAME}}'. Do NOT use 'environmentVariables.VAR_NAME' or env.
203233
234+
${codeGenerationSchemaContext}
235+
204236
Current code: {context}
205237
206238
IMPORTANT FORMATTING RULES:
@@ -373,24 +405,6 @@ try {
373405
}
374406
}
375407

376-
const schemaParameters = useMemo(() => {
377-
try {
378-
if (!jsonSchema) return []
379-
const parsed = JSON.parse(jsonSchema)
380-
const properties = parsed?.function?.parameters?.properties
381-
if (!properties) return []
382-
383-
return Object.keys(properties).map((key) => ({
384-
name: key,
385-
type: properties[key].type || 'any',
386-
description: properties[key].description || '',
387-
required: parsed?.function?.parameters?.required?.includes(key) || false,
388-
}))
389-
} catch {
390-
return []
391-
}
392-
}, [jsonSchema])
393-
394408
const isSchemaValid = useMemo(() => validateSchema(jsonSchema).isValid, [jsonSchema])
395409

396410
const hasChanges = useMemo(() => {

0 commit comments

Comments
 (0)