diff --git a/apps/sim/lib/copilot/tools/server/blocks/get-block-config.ts b/apps/sim/lib/copilot/tools/server/blocks/get-block-config.ts index ca4a00c3e7..d1acfe336c 100644 --- a/apps/sim/lib/copilot/tools/server/blocks/get-block-config.ts +++ b/apps/sim/lib/copilot/tools/server/blocks/get-block-config.ts @@ -123,6 +123,8 @@ function resolveSubBlockOptions(sb: SubBlockConfig): string[] | undefined { interface OutputFieldSchema { type: string description?: string + properties?: Record + items?: { type: string } } /** @@ -256,6 +258,42 @@ function mapSubBlockTypeToSchemaType(type: string): string { return typeMap[type] || 'string' } +/** + * Extracts a single output field schema, including nested properties + */ +function extractOutputField(def: any): OutputFieldSchema { + if (typeof def === 'string') { + return { type: def } + } + + if (typeof def !== 'object' || def === null) { + return { type: 'any' } + } + + const field: OutputFieldSchema = { + type: def.type || 'any', + } + + if (def.description) { + field.description = def.description + } + + // Include nested properties if present + if (def.properties && typeof def.properties === 'object') { + field.properties = {} + for (const [propKey, propDef] of Object.entries(def.properties)) { + field.properties[propKey] = extractOutputField(propDef) + } + } + + // Include items schema for arrays + if (def.items && typeof def.items === 'object') { + field.items = { type: def.items.type || 'any' } + } + + return field +} + /** * Extracts trigger outputs from the first available trigger */ @@ -272,15 +310,7 @@ function extractTriggerOutputs(blockConfig: any): Record