Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 41 additions & 23 deletions apps/sim/lib/copilot/tools/server/blocks/get-block-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ function resolveSubBlockOptions(sb: SubBlockConfig): string[] | undefined {
interface OutputFieldSchema {
type: string
description?: string
properties?: Record<string, OutputFieldSchema>
items?: { type: string }
}

/**
Expand Down Expand Up @@ -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
*/
Expand All @@ -272,15 +310,7 @@ function extractTriggerOutputs(blockConfig: any): Record<string, OutputFieldSche
const trigger = getTrigger(triggerId)
if (trigger.outputs) {
for (const [key, def] of Object.entries(trigger.outputs)) {
if (typeof def === 'string') {
outputs[key] = { type: def }
} else if (typeof def === 'object' && def !== null) {
const typedDef = def as { type?: string; description?: string }
outputs[key] = {
type: typedDef.type || 'any',
description: typedDef.description,
}
}
outputs[key] = extractOutputField(def)
}
}
}
Expand Down Expand Up @@ -312,11 +342,7 @@ function extractOutputs(
const tool = toolsRegistry[toolId]
if (tool?.outputs) {
for (const [key, def] of Object.entries(tool.outputs)) {
const typedDef = def as { type: string; description?: string }
outputs[key] = {
type: typedDef.type || 'any',
description: typedDef.description,
}
outputs[key] = extractOutputField(def)
}
return outputs
}
Expand All @@ -329,15 +355,7 @@ function extractOutputs(
// Use block-level outputs
if (blockConfig.outputs) {
for (const [key, def] of Object.entries(blockConfig.outputs)) {
if (typeof def === 'string') {
outputs[key] = { type: def }
} else if (typeof def === 'object' && def !== null) {
const typedDef = def as { type?: string; description?: string }
outputs[key] = {
type: typedDef.type || 'any',
description: typedDef.description,
}
}
outputs[key] = extractOutputField(def)
}
}

Expand Down