mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-09-09 08:03:50 +00:00
fix tool validation (#7482)
This commit is contained in:
@@ -43,7 +43,7 @@ console.log('✓ Minified OpenFlow JSON generated');
|
||||
console.log(' Original: ' + (originalSize / 1024).toFixed(1) + ' KB → Minified: ' + (minifiedSize / 1024).toFixed(1) + ' KB (saved ' + savings + '%)');
|
||||
|
||||
// === 2. Generate Zod schema ===
|
||||
// Inline \$refs, treating circular references as z.object({}).passthrough()
|
||||
// Inline \$refs, treating circular references with distinct placeholders
|
||||
function inlineRefs(obj, seenRefs = new Set()) {
|
||||
if (typeof obj !== 'object' || obj === null) return obj;
|
||||
if (Array.isArray(obj)) return obj.map(item => inlineRefs(item, seenRefs));
|
||||
@@ -53,8 +53,9 @@ function inlineRefs(obj, seenRefs = new Set()) {
|
||||
if (match) {
|
||||
const refName = match[1];
|
||||
if (seenRefs.has(refName)) {
|
||||
// Mark circular ref with placeholder for z.lazy() replacement
|
||||
return { type: 'string', const: '__CIRCULAR_REF_FLOWMODULE__' };
|
||||
// Mark circular ref with placeholder based on which schema is being referenced
|
||||
// FlowModule is for loops (modules array), FlowModuleValue is for AI agent tools
|
||||
return { type: 'string', const: '__CIRCULAR_REF_' + refName.toUpperCase() + '__' };
|
||||
}
|
||||
if (definitions[refName]) {
|
||||
return inlineRefs(definitions[refName], new Set([...seenRefs, refName]));
|
||||
@@ -70,15 +71,38 @@ function inlineRefs(obj, seenRefs = new Set()) {
|
||||
return result;
|
||||
}
|
||||
|
||||
const inlinedSchema = inlineRefs(definitions.FlowModule, new Set(['FlowModule']));
|
||||
// Generate FlowModuleValue schema first (needed for AI agent tools)
|
||||
const inlinedValueSchema = inlineRefs(definitions.FlowModuleValue, new Set(['FlowModuleValue']));
|
||||
let valueZodCode = jsonSchemaToZod(inlinedValueSchema, { name: 'flowModuleValueSchema', module: 'esm' });
|
||||
|
||||
// Generate FlowModule schema (the full module with id wrapper)
|
||||
const inlinedSchema = inlineRefs(definitions.FlowModule, new Set(['FlowModule']));
|
||||
let zodCode = jsonSchemaToZod(inlinedSchema, { name: 'flowModuleSchema', module: 'esm' });
|
||||
|
||||
// Replace circular reference placeholders with z.lazy() for proper recursive typing
|
||||
zodCode = zodCode.replace(/z\.literal\(\"__CIRCULAR_REF_FLOWMODULE__\"\)/g, 'z.lazy(() => flowModuleSchema)');
|
||||
// Remove the import line from valueZodCode to get just the schema definition
|
||||
// The import looks like: import { z } from \"zod\"\\n\\n
|
||||
let valueSchemaExport = valueZodCode.replace(/^import[^\\n]*\\n\\n?/, '');
|
||||
|
||||
// Replace circular reference placeholders with appropriate z.lazy() calls in valueZodCode
|
||||
valueSchemaExport = valueSchemaExport
|
||||
.replace(/z\\.literal\\(\"__CIRCULAR_REF_FLOWMODULE__\"\\)/g, 'z.lazy(() => flowModuleSchema)')
|
||||
.replace(/z\\.literal\\(\"__CIRCULAR_REF_FLOWMODULEVALUE__\"\\)/g, 'z.lazy(() => flowModuleValueSchema)');
|
||||
|
||||
// Replace circular reference placeholders in zodCode
|
||||
// FlowModule is used for loops (modules array)
|
||||
zodCode = zodCode.replace(/z\\.literal\\(\"__CIRCULAR_REF_FLOWMODULE__\"\\)/g, 'z.lazy(() => flowModuleSchema)');
|
||||
// FlowModuleValue is used for AI agent tool values
|
||||
zodCode = zodCode.replace(/z\\.literal\\(\"__CIRCULAR_REF_FLOWMODULEVALUE__\"\\)/g, 'z.lazy(() => flowModuleValueSchema)');
|
||||
|
||||
zodCode = zodCode.replace('from \"zod\"', 'from \"zod/v3\"');
|
||||
zodCode += '\n\nexport const flowModulesSchema = z.array(flowModuleSchema)\n';
|
||||
|
||||
// Insert the valueSchemaExport before flowModuleSchema definition
|
||||
zodCode = zodCode.replace(
|
||||
'export const flowModuleSchema',
|
||||
valueSchemaExport + '\\n\\nexport const flowModuleSchema'
|
||||
);
|
||||
|
||||
zodCode += '\\n\\nexport const flowModulesSchema = z.array(flowModuleSchema)\\n';
|
||||
|
||||
fs.writeFileSync(zodOutputFile, zodCode);
|
||||
console.log('✓ Generated Zod schema: ' + zodOutputFile);
|
||||
|
||||
@@ -172,6 +172,12 @@
|
||||
},
|
||||
|
||||
getLintErrors: async (moduleId: string): Promise<ScriptLintResult> => {
|
||||
|
||||
const module = getModule(moduleId)
|
||||
if (!module || module.value.type !== 'rawscript') {
|
||||
return { errorCount: 0, warningCount: 0, errors: [], warnings: [] }
|
||||
}
|
||||
|
||||
// Focus the module first
|
||||
selectionManager.selectId(moduleId)
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user