Skip to content

Commit 0be52a4

Browse files
committed
improvement(copilot): tool configs to show nested props
1 parent f3fcc28 commit 0be52a4

File tree

1 file changed

+41
-23
lines changed

1 file changed

+41
-23
lines changed

apps/sim/lib/copilot/tools/server/blocks/get-block-config.ts

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ function resolveSubBlockOptions(sb: SubBlockConfig): string[] | undefined {
123123
interface OutputFieldSchema {
124124
type: string
125125
description?: string
126+
properties?: Record<string, OutputFieldSchema>
127+
items?: { type: string }
126128
}
127129

128130
/**
@@ -256,6 +258,42 @@ function mapSubBlockTypeToSchemaType(type: string): string {
256258
return typeMap[type] || 'string'
257259
}
258260

261+
/**
262+
* Extracts a single output field schema, including nested properties
263+
*/
264+
function extractOutputField(def: any): OutputFieldSchema {
265+
if (typeof def === 'string') {
266+
return { type: def }
267+
}
268+
269+
if (typeof def !== 'object' || def === null) {
270+
return { type: 'any' }
271+
}
272+
273+
const field: OutputFieldSchema = {
274+
type: def.type || 'any',
275+
}
276+
277+
if (def.description) {
278+
field.description = def.description
279+
}
280+
281+
// Include nested properties if present
282+
if (def.properties && typeof def.properties === 'object') {
283+
field.properties = {}
284+
for (const [propKey, propDef] of Object.entries(def.properties)) {
285+
field.properties[propKey] = extractOutputField(propDef)
286+
}
287+
}
288+
289+
// Include items schema for arrays
290+
if (def.items && typeof def.items === 'object') {
291+
field.items = { type: def.items.type || 'any' }
292+
}
293+
294+
return field
295+
}
296+
259297
/**
260298
* Extracts trigger outputs from the first available trigger
261299
*/
@@ -272,15 +310,7 @@ function extractTriggerOutputs(blockConfig: any): Record<string, OutputFieldSche
272310
const trigger = getTrigger(triggerId)
273311
if (trigger.outputs) {
274312
for (const [key, def] of Object.entries(trigger.outputs)) {
275-
if (typeof def === 'string') {
276-
outputs[key] = { type: def }
277-
} else if (typeof def === 'object' && def !== null) {
278-
const typedDef = def as { type?: string; description?: string }
279-
outputs[key] = {
280-
type: typedDef.type || 'any',
281-
description: typedDef.description,
282-
}
283-
}
313+
outputs[key] = extractOutputField(def)
284314
}
285315
}
286316
}
@@ -312,11 +342,7 @@ function extractOutputs(
312342
const tool = toolsRegistry[toolId]
313343
if (tool?.outputs) {
314344
for (const [key, def] of Object.entries(tool.outputs)) {
315-
const typedDef = def as { type: string; description?: string }
316-
outputs[key] = {
317-
type: typedDef.type || 'any',
318-
description: typedDef.description,
319-
}
345+
outputs[key] = extractOutputField(def)
320346
}
321347
return outputs
322348
}
@@ -329,15 +355,7 @@ function extractOutputs(
329355
// Use block-level outputs
330356
if (blockConfig.outputs) {
331357
for (const [key, def] of Object.entries(blockConfig.outputs)) {
332-
if (typeof def === 'string') {
333-
outputs[key] = { type: def }
334-
} else if (typeof def === 'object' && def !== null) {
335-
const typedDef = def as { type?: string; description?: string }
336-
outputs[key] = {
337-
type: typedDef.type || 'any',
338-
description: typedDef.description,
339-
}
340-
}
358+
outputs[key] = extractOutputField(def)
341359
}
342360
}
343361

0 commit comments

Comments
 (0)